@mintlify/http-client 0.0.5 → 0.0.7

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.
Files changed (57) hide show
  1. package/LICENSE +93 -0
  2. package/README.md +16 -16
  3. package/dist/client/baseClient.d.ts +63 -63
  4. package/dist/client/baseClient.js +93 -93
  5. package/dist/client/clientError.d.ts +32 -32
  6. package/dist/client/clientError.js +88 -88
  7. package/dist/client/index.d.ts +6 -6
  8. package/dist/client/index.js +7 -7
  9. package/dist/client/interfaces.d.ts +93 -93
  10. package/dist/client/interfaces.js +2 -2
  11. package/dist/client/types.d.ts +9 -9
  12. package/dist/client/types.js +2 -2
  13. package/dist/index.d.ts +7 -7
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +18 -18
  16. package/dist/leaves-client/constants.d.ts +21 -18
  17. package/dist/leaves-client/constants.d.ts.map +1 -1
  18. package/dist/leaves-client/constants.js +19 -16
  19. package/dist/leaves-client/constants.js.map +1 -1
  20. package/dist/leaves-client/index.d.ts +5 -5
  21. package/dist/leaves-client/index.js +23 -23
  22. package/dist/leaves-client/interfaces.d.ts +18 -16
  23. package/dist/leaves-client/interfaces.d.ts.map +1 -1
  24. package/dist/leaves-client/interfaces.js +2 -2
  25. package/dist/leaves-client/leavesClient.d.ts +7 -7
  26. package/dist/leaves-client/leavesClient.d.ts.map +1 -1
  27. package/dist/leaves-client/leavesClient.js +95 -92
  28. package/dist/leaves-client/leavesClient.js.map +1 -1
  29. package/dist/leaves-client/types.d.ts +7 -11
  30. package/dist/leaves-client/types.d.ts.map +1 -1
  31. package/dist/leaves-client/types.js +2 -2
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +78 -77
  34. package/dist/setup-jest.d.ts +0 -1
  35. package/dist/setup-jest.js +0 -5
  36. package/dist/src/client/baseClient.d.ts +0 -63
  37. package/dist/src/client/baseClient.js +0 -180
  38. package/dist/src/client/clientError.d.ts +0 -32
  39. package/dist/src/client/clientError.js +0 -160
  40. package/dist/src/client/index.d.ts +0 -6
  41. package/dist/src/client/index.js +0 -7
  42. package/dist/src/client/interfaces.d.ts +0 -93
  43. package/dist/src/client/interfaces.js +0 -2
  44. package/dist/src/client/types.d.ts +0 -9
  45. package/dist/src/client/types.js +0 -2
  46. package/dist/src/index.d.ts +0 -2
  47. package/dist/src/index.js +0 -18
  48. package/dist/src/leaves-client/constants.d.ts +0 -18
  49. package/dist/src/leaves-client/constants.js +0 -16
  50. package/dist/src/leaves-client/index.d.ts +0 -4
  51. package/dist/src/leaves-client/index.js +0 -8
  52. package/dist/src/leaves-client/interfaces.d.ts +0 -15
  53. package/dist/src/leaves-client/interfaces.js +0 -2
  54. package/dist/src/leaves-client/leavesClient.d.ts +0 -7
  55. package/dist/src/leaves-client/leavesClient.js +0 -157
  56. package/dist/src/leaves-client/types.d.ts +0 -11
  57. package/dist/src/leaves-client/types.js +0 -2
@@ -1,93 +0,0 @@
1
- import { ErrorResponseType, HttpMethods, QueryType, RequestInitType } from './types';
2
- /**
3
- * The `IBaseClient` interface outlines the structure for a base client with basic configurations for making HTTP requests.
4
- */
5
- export interface IBaseClient {
6
- /**
7
- * The server's address to which the client makes requests.
8
- */
9
- readonly host: string;
10
- /**
11
- * Fetches a response from the given path.
12
- * @param path - The path of the resource.
13
- * @param query - Optional query.
14
- * @param init - Optional request initializer. Overwrites default settings.
15
- */
16
- fetch(path: string, query?: QueryType, init?: RequestInit): Promise<{
17
- uri: string;
18
- res: Response;
19
- }>;
20
- /**
21
- * Gets a response from the given path.
22
- * @param path - The path of the resource.
23
- * @param query - Optional query.
24
- * @param init - Optional request initializer. Overwrites default settings.
25
- */
26
- get(path: string, query?: QueryType, init?: RequestInit): Promise<Response>;
27
- /**
28
- * Posts a request and gets a response from the given path.
29
- * @param path - The path of the resource.
30
- * @param query - Optional query.
31
- * @param init - Optional request initializer. Overwrites default settings.
32
- * @returns Promise that resolves with the JSON data.
33
- */
34
- post(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
35
- /**
36
- * Fetches a resource as text from the given path.
37
- * @param path - The path of the resource.
38
- * @param query - Optional query.
39
- * @param init - Optional request initializer. Overwrites default settings.
40
- * @returns Promise that resolves with the text data.
41
- */
42
- text(path: string, query?: QueryType, init?: RequestInit): Promise<string>;
43
- /**
44
- * Fetches a resource as JSON from the given path.
45
- * @param path - The path of the resource.
46
- * @param query - Optional query.
47
- * @param init - Optional request initializer. Overwrites default settings.
48
- * @returns Promise that resolves with the JSON data.
49
- */
50
- json<T extends object>(path: string, query?: QueryType, init?: RequestInit): Promise<T>;
51
- /**
52
- * Fetches a response, using the given path and method.
53
- * @param method = Http method of the request.
54
- * @param path - The path of the resource.
55
- * @param query - Optional query.
56
- * @param init - Optional request initializer. Overwrites default settings.
57
- */
58
- method(method: HttpMethods, path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
59
- /**
60
- * Constructs a URI path by joining URI components.
61
- * @param paths - Paths to encode and join.
62
- * @returns encoded URI path.
63
- */
64
- getPath(...paths: string[]): string;
65
- /**
66
- * Constructs a URI by appending a path to the host.
67
- * @param path - The path to append to the host.
68
- * @returns URI string.
69
- */
70
- getUri(path: string): string;
71
- }
72
- /**
73
- * Outlines the structure for a custom error type to handle client errors.
74
- * It extends the built-in Error interface.
75
- */
76
- export interface IClientError extends Error {
77
- /**
78
- * `BaseClient` that is associated with the error.
79
- */
80
- readonly client: IBaseClient;
81
- /**
82
- * Response received from the server that caused the error.
83
- */
84
- readonly response: ErrorResponseType;
85
- /**
86
- * Optional request that was sent which caused the error.
87
- */
88
- readonly request?: RequestInit;
89
- /**
90
- * Optional URI to which the request was sent.
91
- */
92
- readonly uri?: string;
93
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- /**
2
- * The `ErrorResponseType` type represents a server response that contains a client side error.
3
- * It includes the mandatory 'status' property from the Response object.
4
- * All other properties are optional.
5
- */
6
- export type ErrorResponseType = Partial<Omit<Response, 'status'>> & Pick<Response, 'status'>;
7
- export type HttpMethods = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace' | 'connect';
8
- export type QueryType = string[][] | Record<string, string> | string | URLSearchParams;
9
- export type RequestInitType = Omit<RequestInit, 'method'>;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- export * from './leaves-client';
2
- export * from './client';
package/dist/src/index.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./leaves-client"), exports);
18
- __exportStar(require("./client"), exports);
@@ -1,18 +0,0 @@
1
- import { ErrorResponseType } from '../client/types';
2
- export declare const ADMIN_TOKEN: string | undefined;
3
- export declare const SUBDOMAIN: string | undefined;
4
- export declare const AUTH_HEADER: {
5
- Authorization: string;
6
- } | undefined;
7
- export declare const API_ENDPOINT: string;
8
- export declare const ENDPOINT: string;
9
- export declare const HEADERS: {
10
- Authorization: string;
11
- } | undefined;
12
- export declare const NAVIGATION_ROUTE = "navigation";
13
- export declare const PATHS_ROUTE = "paths";
14
- export declare const HOSTING_LOCATION_ROUTE = "hosting-location";
15
- export declare const HIDDEN_PAGES_ROUTE = "hidden-pages";
16
- export declare const UNAUTHORIZED: ErrorResponseType;
17
- export declare const ACCESS_DENIED = "Access denied. Not authorized to access protected content.";
18
- export declare const IS_PASSWORD_PROTECTED: boolean;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IS_PASSWORD_PROTECTED = exports.ACCESS_DENIED = exports.UNAUTHORIZED = exports.HIDDEN_PAGES_ROUTE = exports.HOSTING_LOCATION_ROUTE = exports.PATHS_ROUTE = exports.NAVIGATION_ROUTE = exports.HEADERS = exports.ENDPOINT = exports.API_ENDPOINT = exports.AUTH_HEADER = exports.SUBDOMAIN = exports.ADMIN_TOKEN = void 0;
4
- exports.ADMIN_TOKEN = process.env.ADMIN_TOKEN;
5
- exports.SUBDOMAIN = process.env.SUBDOMAIN;
6
- exports.AUTH_HEADER = exports.ADMIN_TOKEN ? { Authorization: "Bearer ".concat(exports.ADMIN_TOKEN) } : undefined;
7
- exports.API_ENDPOINT = process.env.API_ENDPOINT || 'http://localhost:5000';
8
- exports.ENDPOINT = "".concat(exports.API_ENDPOINT, "/api");
9
- exports.HEADERS = exports.AUTH_HEADER;
10
- exports.NAVIGATION_ROUTE = 'navigation';
11
- exports.PATHS_ROUTE = 'paths';
12
- exports.HOSTING_LOCATION_ROUTE = 'hosting-location';
13
- exports.HIDDEN_PAGES_ROUTE = 'hidden-pages';
14
- exports.UNAUTHORIZED = { status: 401 };
15
- exports.ACCESS_DENIED = 'Access denied. Not authorized to access protected content.';
16
- exports.IS_PASSWORD_PROTECTED = process.env.IS_PASSWORD_PROTECTED === 'true';
@@ -1,4 +0,0 @@
1
- import { ILeavesClient } from './interfaces';
2
- import getLeavesClient from './leavesClient';
3
- export { getLeavesClient };
4
- export type { ILeavesClient };
@@ -1,8 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getLeavesClient = void 0;
7
- var leavesClient_1 = __importDefault(require("./leavesClient"));
8
- exports.getLeavesClient = leavesClient_1.default;
@@ -1,15 +0,0 @@
1
- import { DeploymentType, SnippetType, CustomerPageType, NavGroups } from '@mintlify/models';
2
- import { IBaseClient } from '../client';
3
- import { GetPagePropsReturnType } from './types';
4
- export interface ILeavesClient extends IBaseClient {
5
- readonly subdomain: string;
6
- readonly isPasswordProtected: boolean;
7
- getDeployment(): Promise<DeploymentType>;
8
- getNavigation(): Promise<NavGroups>;
9
- getSnippets(): Promise<SnippetType[]>;
10
- getPage(path: string, basePath?: string): Promise<CustomerPageType>;
11
- getHostingLocation(): Promise<string>;
12
- getHiddenPages(): Promise<string[]>;
13
- getPageProps(path: string, basePath?: string): Promise<GetPagePropsReturnType>;
14
- getPaths(): Promise<string[]>;
15
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- import { ILeavesClient } from './interfaces';
2
- export declare const getLeavesClient: (subdomain: string, isPasswordProtected?: boolean, host?: string, reqInit?: {
3
- headers: {
4
- Authorization: string;
5
- } | undefined;
6
- }) => ILeavesClient;
7
- export default getLeavesClient;
@@ -1,157 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
- 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;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- Object.defineProperty(exports, "__esModule", { value: true });
65
- exports.getLeavesClient = void 0;
66
- var models_1 = require("@mintlify/models");
67
- var client_1 = require("../client");
68
- var clientError_1 = require("../client/clientError");
69
- var constants_1 = require("./constants");
70
- var LeavesClient = /** @class */ (function (_super) {
71
- __extends(LeavesClient, _super);
72
- function LeavesClient(subdomain, isPasswordProtected, host, reqInit) {
73
- if (reqInit === void 0) { reqInit = undefined; }
74
- var _this = _super.call(this, host, reqInit) || this;
75
- _this.isPasswordProtected = isPasswordProtected;
76
- _this.subdomain = constants_1.SUBDOMAIN !== null && constants_1.SUBDOMAIN !== void 0 ? constants_1.SUBDOMAIN : subdomain;
77
- var isAccessDenied = constants_1.SUBDOMAIN !== subdomain && _this.isPasswordProtected;
78
- clientError_1.handleAccess.bind(_this)(!isAccessDenied);
79
- return _this;
80
- }
81
- LeavesClient.prototype.getDeployment = function () {
82
- return this.entity(models_1.ENTITY_TYPE.DEPLOYMENT);
83
- };
84
- LeavesClient.prototype.getNavigation = function () {
85
- var path = this.getPath(constants_1.NAVIGATION_ROUTE, this.subdomain);
86
- return this.json(path);
87
- };
88
- LeavesClient.prototype.getSnippets = function () {
89
- return this.entity(models_1.ENTITY_TYPE.SNIPPET);
90
- };
91
- LeavesClient.prototype.getPage = function (path, basePath) {
92
- return this.entity(models_1.ENTITY_TYPE.PAGE, __assign({ path: path }, (basePath ? { basePath: basePath } : {})));
93
- };
94
- LeavesClient.prototype.getHiddenPages = function () {
95
- var route = this.getRoute(models_1.ENTITY_TYPE.PAGE);
96
- var path = this.getPath(route, this.subdomain, constants_1.HIDDEN_PAGES_ROUTE);
97
- return this.json(path);
98
- };
99
- LeavesClient.prototype.getPaths = function () {
100
- var route = this.getRoute(models_1.ENTITY_TYPE.PAGE);
101
- var path = this.getPath(route, this.subdomain, constants_1.PATHS_ROUTE);
102
- return this.json(path);
103
- };
104
- LeavesClient.prototype.getHostingLocation = function () {
105
- var route = this.getRoute(models_1.ENTITY_TYPE.DEPLOYMENT);
106
- var path = this.getPath(route, this.subdomain, constants_1.HOSTING_LOCATION_ROUTE);
107
- return this.text(path);
108
- };
109
- LeavesClient.prototype.getPageProps = function (path, basePath) {
110
- var _a;
111
- return __awaiter(this, void 0, void 0, function () {
112
- var promises, _b, deployment, page, isProtectedEqual;
113
- return __generator(this, function (_c) {
114
- switch (_c.label) {
115
- case 0:
116
- promises = [
117
- this.getDeployment(),
118
- this.getPage(path, basePath),
119
- ];
120
- return [4 /*yield*/, Promise.all(promises)];
121
- case 1:
122
- _b = _c.sent(), deployment = _b[0], page = _b[1];
123
- isProtectedEqual = this.isPasswordProtected === ((_a = deployment.isPasswordProtected) !== null && _a !== void 0 ? _a : false);
124
- clientError_1.handleAccess.bind(this)(isProtectedEqual);
125
- return [2 /*return*/, {
126
- data: __assign(__assign({}, deployment), page),
127
- status: 200,
128
- }];
129
- }
130
- });
131
- });
132
- };
133
- LeavesClient.prototype.getRoute = function (type) {
134
- switch (type) {
135
- case models_1.ENTITY_TYPE.DEPLOYMENT:
136
- case models_1.ENTITY_TYPE.SNIPPET:
137
- case models_1.ENTITY_TYPE.PAGE:
138
- return type.toLowerCase();
139
- default:
140
- throw new Error("ENTITY_TYPE: ".concat(type, " is not supported."));
141
- }
142
- };
143
- LeavesClient.prototype.entity = function (type, query, init) {
144
- var route = this.getRoute(type);
145
- var path = this.getPath(route, this.subdomain);
146
- return this.json(path, query, init);
147
- };
148
- return LeavesClient;
149
- }(client_1.BaseClient));
150
- var getLeavesClient = function (subdomain, isPasswordProtected, host, reqInit) {
151
- if (isPasswordProtected === void 0) { isPasswordProtected = constants_1.IS_PASSWORD_PROTECTED; }
152
- if (host === void 0) { host = constants_1.ENDPOINT; }
153
- if (reqInit === void 0) { reqInit = { headers: constants_1.HEADERS }; }
154
- return new LeavesClient(subdomain, isPasswordProtected, host, reqInit);
155
- };
156
- exports.getLeavesClient = getLeavesClient;
157
- exports.default = exports.getLeavesClient;
@@ -1,11 +0,0 @@
1
- import { CustomerPageType, DeploymentType } from '@mintlify/models';
2
- export type PagePropsResponseType = CustomerPageType & DeploymentType & {
3
- redirect?: {
4
- destination: string;
5
- permanent: boolean;
6
- };
7
- };
8
- export type GetPagePropsReturnType = {
9
- data?: PagePropsResponseType;
10
- status: number;
11
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });