@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.
@@ -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
- var LeavesClient = /** @class */ (function (_super) {
68
- __extends(LeavesClient, _super);
69
- function LeavesClient(subdomain, isPasswordProtected, host, reqInit) {
70
- if (reqInit === void 0) { reqInit = undefined; }
71
- var _this = _super.call(this, host, reqInit) || this;
72
- _this.isPasswordProtected = isPasswordProtected;
73
- _this.subdomain = SUBDOMAIN !== null && SUBDOMAIN !== void 0 ? SUBDOMAIN : subdomain;
74
- var isAccessDenied = SUBDOMAIN !== subdomain && _this.isPasswordProtected;
75
- handleAccess.bind(_this)(!isAccessDenied);
76
- return _this;
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
- LeavesClient.prototype.getDeployment = function () {
79
- return this.entity(ENTITY_TYPE.DEPLOYMENT);
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
- LeavesClient.prototype.getSnippets = function () {
86
- return this.entity(ENTITY_TYPE.SNIPPET);
87
- };
88
- LeavesClient.prototype.getPage = function (path, basePath) {
89
- return this.entity(ENTITY_TYPE.PAGE, __assign({ path: path }, (basePath ? { basePath: basePath } : {})));
90
- };
91
- LeavesClient.prototype.getHiddenPages = function () {
92
- var route = this.getRoute(ENTITY_TYPE.PAGE);
93
- var path = this.getPath(route, this.subdomain, HIDDEN_PAGES_ROUTE);
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
- LeavesClient.prototype.getPaths = function () {
97
- var route = this.getRoute(ENTITY_TYPE.PAGE);
98
- var path = this.getPath(route, this.subdomain, PATHS_ROUTE);
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
- LeavesClient.prototype.getHostingLocation = function () {
102
- var route = this.getRoute(ENTITY_TYPE.DEPLOYMENT);
103
- var path = this.getPath(route, this.subdomain, HOSTING_LOCATION_ROUTE);
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
- LeavesClient.prototype.getPageProps = function (path, basePath) {
107
- var _a;
108
- return __awaiter(this, void 0, void 0, function () {
109
- var promises, _b, deployment, page, isProtectedEqual;
110
- return __generator(this, function (_c) {
111
- switch (_c.label) {
112
- case 0:
113
- promises = [
114
- this.getDeployment(),
115
- this.getPage(path, basePath),
116
- ];
117
- return [4 /*yield*/, Promise.all(promises)];
118
- case 1:
119
- _b = _c.sent(), deployment = _b[0], page = _b[1];
120
- isProtectedEqual = this.isPasswordProtected === ((_a = deployment.isPasswordProtected) !== null && _a !== void 0 ? _a : false);
121
- handleAccess.bind(this)(isProtectedEqual);
122
- return [2 /*return*/, {
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("ENTITY_TYPE: ".concat(type, " is not supported."));
75
+ throw new Error(`ENTITY_TYPE: ${type} is not supported.`);
138
76
  }
139
- };
140
- LeavesClient.prototype.entity = function (type, query, init) {
141
- var route = this.getRoute(type);
142
- var path = this.getPath(route, this.subdomain);
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
- return LeavesClient;
146
- }(BaseClient));
147
- export var getLeavesClient = function (subdomain, isPasswordProtected, host, reqInit) {
148
- if (isPasswordProtected === void 0) { isPasswordProtected = IS_PASSWORD_PROTECTED; }
149
- if (host === void 0) { host = ENDPOINT; }
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;