@mintlify/http-client 0.0.2 → 0.0.4
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/README.md +14 -2
- package/dist/client/baseClient.js +46 -134
- package/dist/client/clientError.js +24 -96
- package/dist/leaves-client/constants.js +13 -13
- package/dist/leaves-client/interfaces.d.ts +2 -1
- package/dist/leaves-client/leavesClient.js +74 -139
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
|
@@ -1,153 +1,88 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
|
17
|
-
__assign = Object.assign || function(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
-
t[p] = s[p];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
return __assign.apply(this, arguments);
|
|
26
|
-
};
|
|
27
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
28
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
29
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
37
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
38
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
39
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
40
|
-
function step(op) {
|
|
41
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
42
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
43
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
44
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
45
|
-
switch (op[0]) {
|
|
46
|
-
case 0: case 1: t = op; break;
|
|
47
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
48
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
49
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
50
|
-
default:
|
|
51
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
52
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
53
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
54
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
55
|
-
if (t[2]) _.ops.pop();
|
|
56
|
-
_.trys.pop(); continue;
|
|
57
|
-
}
|
|
58
|
-
op = body.call(thisArg, _);
|
|
59
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
60
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
import { ENTITY_TYPE, } from '@mintlify/models';
|
|
64
1
|
import { BaseClient } from '../client';
|
|
65
2
|
import { handleAccess } from '../client/clientError';
|
|
66
3
|
import { ENDPOINT, HEADERS, HIDDEN_PAGES_ROUTE, HOSTING_LOCATION_ROUTE, IS_PASSWORD_PROTECTED, NAVIGATION_ROUTE, PATHS_ROUTE, SUBDOMAIN, } from './constants';
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return
|
|
4
|
+
class LeavesClient extends BaseClient {
|
|
5
|
+
constructor(subdomain, isPasswordProtected, host, reqInit = undefined) {
|
|
6
|
+
super(host, reqInit);
|
|
7
|
+
this.isPasswordProtected = isPasswordProtected;
|
|
8
|
+
this.subdomain = SUBDOMAIN ?? subdomain;
|
|
9
|
+
const isAccessDenied = SUBDOMAIN !== subdomain && this.isPasswordProtected;
|
|
10
|
+
handleAccess.bind(this)(!isAccessDenied);
|
|
11
|
+
}
|
|
12
|
+
getDeployment() {
|
|
13
|
+
return this.entity("deployment" /* ENTITY_TYPE.DEPLOYMENT */);
|
|
77
14
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
LeavesClient.prototype.getNavigation = function () {
|
|
82
|
-
var path = this.getPath(NAVIGATION_ROUTE, this.subdomain);
|
|
15
|
+
getNavigation() {
|
|
16
|
+
const path = this.getPath(NAVIGATION_ROUTE, this.subdomain);
|
|
83
17
|
return this.json(path);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return this.entity(ENTITY_TYPE.SNIPPET);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return this.entity(ENTITY_TYPE.PAGE
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
18
|
+
}
|
|
19
|
+
getSnippets() {
|
|
20
|
+
return this.entity("snippet" /* ENTITY_TYPE.SNIPPET */);
|
|
21
|
+
}
|
|
22
|
+
getPage(path, basePath, ...fields) {
|
|
23
|
+
return this.entity("page" /* ENTITY_TYPE.PAGE */, {
|
|
24
|
+
path,
|
|
25
|
+
...this.getFields(fields),
|
|
26
|
+
...(basePath ? { basePath } : {}),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
getPages(basePath, ...fields) {
|
|
30
|
+
const route = this.getRoute("page" /* ENTITY_TYPE.PAGE */);
|
|
31
|
+
const path = this.getPath(route, this.subdomain, 'list');
|
|
32
|
+
return this.json(path, {
|
|
33
|
+
...this.getFields(fields),
|
|
34
|
+
...(basePath ? { basePath } : {}),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getHiddenPages() {
|
|
38
|
+
const route = this.getRoute("page" /* ENTITY_TYPE.PAGE */);
|
|
39
|
+
const path = this.getPath(route, this.subdomain, HIDDEN_PAGES_ROUTE);
|
|
94
40
|
return this.json(path);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
41
|
+
}
|
|
42
|
+
getPaths() {
|
|
43
|
+
const route = this.getRoute("page" /* ENTITY_TYPE.PAGE */);
|
|
44
|
+
const path = this.getPath(route, this.subdomain, PATHS_ROUTE);
|
|
99
45
|
return this.json(path);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
46
|
+
}
|
|
47
|
+
getHostingLocation() {
|
|
48
|
+
const route = this.getRoute("deployment" /* ENTITY_TYPE.DEPLOYMENT */);
|
|
49
|
+
const path = this.getPath(route, this.subdomain, HOSTING_LOCATION_ROUTE);
|
|
104
50
|
return this.text(path);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
data: __assign(__assign({}, deployment), page),
|
|
124
|
-
status: 200,
|
|
125
|
-
}];
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
LeavesClient.prototype.getRoute = function (type) {
|
|
51
|
+
}
|
|
52
|
+
async getPageProps(path, basePath) {
|
|
53
|
+
const promises = [
|
|
54
|
+
this.getDeployment(),
|
|
55
|
+
this.getPage(path, basePath),
|
|
56
|
+
];
|
|
57
|
+
const [deployment, page] = await Promise.all(promises);
|
|
58
|
+
const isProtectedEqual = this.isPasswordProtected === (deployment.isPasswordProtected ?? false);
|
|
59
|
+
handleAccess.bind(this)(isProtectedEqual);
|
|
60
|
+
return {
|
|
61
|
+
data: {
|
|
62
|
+
...deployment,
|
|
63
|
+
...page,
|
|
64
|
+
},
|
|
65
|
+
status: 200,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
getRoute(type) {
|
|
131
69
|
switch (type) {
|
|
132
|
-
case ENTITY_TYPE.DEPLOYMENT
|
|
133
|
-
case ENTITY_TYPE.SNIPPET
|
|
134
|
-
case ENTITY_TYPE.PAGE
|
|
70
|
+
case "deployment" /* ENTITY_TYPE.DEPLOYMENT */:
|
|
71
|
+
case "snippet" /* ENTITY_TYPE.SNIPPET */:
|
|
72
|
+
case "page" /* ENTITY_TYPE.PAGE */:
|
|
135
73
|
return type.toLowerCase();
|
|
136
74
|
default:
|
|
137
|
-
throw new Error(
|
|
75
|
+
throw new Error(`ENTITY_TYPE: ${type} is not supported.`);
|
|
138
76
|
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
77
|
+
}
|
|
78
|
+
entity(type, query, init) {
|
|
79
|
+
const route = this.getRoute(type);
|
|
80
|
+
const path = this.getPath(route, this.subdomain);
|
|
143
81
|
return this.json(path, query, init);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (reqInit === void 0) { reqInit = { headers: HEADERS }; }
|
|
151
|
-
return new LeavesClient(subdomain, isPasswordProtected, host, reqInit);
|
|
152
|
-
};
|
|
82
|
+
}
|
|
83
|
+
getFields(fields) {
|
|
84
|
+
return (fields?.length ?? 0) > 0 ? { fields: JSON.stringify(fields) } : {};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export const getLeavesClient = (subdomain, isPasswordProtected = IS_PASSWORD_PROTECTED, host = ENDPOINT, reqInit = { headers: HEADERS }) => new LeavesClient(subdomain, isPasswordProtected, host, reqInit);
|
|
153
88
|
export default getLeavesClient;
|