@newfold/huapi-js 1.2.2 → 1.2.5

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/huapi.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ exports.__esModule = true;
14
+ exports.getHostingUAPIMSW = exports.getHostingSiteByIdMock = exports.getHostingSitesMock = exports.getSiteSsoMock = exports.useHostingSiteById = exports.getHostingSiteByIdQueryKey = exports.hostingSiteById = exports.useHostingSites = exports.getHostingSitesQueryKey = exports.hostingSites = exports.useSiteSso = exports.siteSso = void 0;
15
+ /**
16
+ * Generated by orval v6.7.1 🍺
17
+ * Do not edit manually.
18
+ * Hosting UAPI
19
+ * Hosting UAPI
20
+ * OpenAPI spec version: 0.1.0
21
+ */
22
+ var axios_1 = require("axios");
23
+ var react_query_1 = require("react-query");
24
+ var msw_1 = require("msw");
25
+ /**
26
+ * TODO
27
+ * @summary Get SSO token
28
+ */
29
+ var siteSso = function (siteId, options) {
30
+ return axios_1["default"].post("/sites/".concat(siteId, "/sso"), undefined, options);
31
+ };
32
+ exports.siteSso = siteSso;
33
+ var useSiteSso = function (options) {
34
+ var _a = options || {}, mutationOptions = _a.mutation, axiosOptions = _a.axios;
35
+ var mutationFn = function (props) {
36
+ var siteId = (props || {}).siteId;
37
+ return (0, exports.siteSso)(siteId, axiosOptions);
38
+ };
39
+ return (0, react_query_1.useMutation)(mutationFn, mutationOptions);
40
+ };
41
+ exports.useSiteSso = useSiteSso;
42
+ /**
43
+ * Obtain a list of sites.
44
+ * @summary Get sites for a hosting id
45
+ */
46
+ var hostingSites = function (hostingId, options) {
47
+ return axios_1["default"].get("/hosting/".concat(hostingId, "/sites"), options);
48
+ };
49
+ exports.hostingSites = hostingSites;
50
+ var getHostingSitesQueryKey = function (hostingId) { return ["/hosting/".concat(hostingId, "/sites")]; };
51
+ exports.getHostingSitesQueryKey = getHostingSitesQueryKey;
52
+ var useHostingSites = function (hostingId, options) {
53
+ var _a;
54
+ var _b = options || {}, queryOptions = _b.query, axiosOptions = _b.axios;
55
+ var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.getHostingSitesQueryKey)(hostingId);
56
+ var queryFn = function () { return (0, exports.hostingSites)(hostingId, axiosOptions); };
57
+ var query = (0, react_query_1.useQuery)(queryKey, queryFn, __assign({ enabled: !!(hostingId) }, queryOptions));
58
+ return __assign({ queryKey: queryKey }, query);
59
+ };
60
+ exports.useHostingSites = useHostingSites;
61
+ /**
62
+ * Obtain a specific site.
63
+ * @summary For a hosting id, get a specific site by site id
64
+ */
65
+ var hostingSiteById = function (hostingId, siteId, options) {
66
+ return axios_1["default"].get("/hosting/".concat(hostingId, "/sites/").concat(siteId), options);
67
+ };
68
+ exports.hostingSiteById = hostingSiteById;
69
+ var getHostingSiteByIdQueryKey = function (hostingId, siteId) { return ["/hosting/".concat(hostingId, "/sites/").concat(siteId)]; };
70
+ exports.getHostingSiteByIdQueryKey = getHostingSiteByIdQueryKey;
71
+ var useHostingSiteById = function (hostingId, siteId, options) {
72
+ var _a;
73
+ var _b = options || {}, queryOptions = _b.query, axiosOptions = _b.axios;
74
+ var queryKey = (_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.queryKey) !== null && _a !== void 0 ? _a : (0, exports.getHostingSiteByIdQueryKey)(hostingId, siteId);
75
+ var queryFn = function () { return (0, exports.hostingSiteById)(hostingId, siteId, axiosOptions); };
76
+ var query = (0, react_query_1.useQuery)(queryKey, queryFn, __assign({ enabled: !!(hostingId && siteId) }, queryOptions));
77
+ return __assign({ queryKey: queryKey }, query);
78
+ };
79
+ exports.useHostingSiteById = useHostingSiteById;
80
+ var getSiteSsoMock = function () { return ('https://bobtheblog.com/wp-login.php?ssotoken=1234567890'); };
81
+ exports.getSiteSsoMock = getSiteSsoMock;
82
+ var getHostingSitesMock = function () { return ({ limit: 10, n_pages: 1, n_rows: 3, page: 1, rows: [{ id: '1', name: 'Bob the Blog', url: 'https://bobtheblog.com' }, { id: '2', name: 'Wendy the Website', url: 'https://wendythewebsite.com' }, { id: '3', name: 'Cathy the Coding Camp', url: 'https://cathythecodingcamp.com' }] }); };
83
+ exports.getHostingSitesMock = getHostingSitesMock;
84
+ var getHostingSiteByIdMock = function () { return ({ id: '1', name: 'Bob the Blog', url: 'https://bobtheblog.com' }); };
85
+ exports.getHostingSiteByIdMock = getHostingSiteByIdMock;
86
+ var getHostingUAPIMSW = function () { return [
87
+ msw_1.rest.post('*/sites/:siteid/sso', function (_req, res, ctx) {
88
+ return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getSiteSsoMock)()));
89
+ }), msw_1.rest.get('*/hosting/:hostingid/sites', function (_req, res, ctx) {
90
+ return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getHostingSitesMock)()));
91
+ }), msw_1.rest.get('*/hosting/:hostingid/sites/:siteid', function (_req, res, ctx) {
92
+ return res(ctx.delay(1000), ctx.status(200, 'Mocked status'), ctx.json((0, exports.getHostingSiteByIdMock)()));
93
+ }),
94
+ ]; };
95
+ exports.getHostingUAPIMSW = getHostingUAPIMSW;
package/package.json CHANGED
@@ -1,28 +1,25 @@
1
1
  {
2
2
  "name": "@newfold/huapi-js",
3
- "version": "1.2.2",
3
+ "version": "1.2.5",
4
4
  "main": "dist/huapi.js",
5
5
  "license": "MIT",
6
- "devDependencies": {
6
+ "dependencies": {
7
7
  "@faker-js/faker": "^6.1.2",
8
8
  "axios": "^0.26.1",
9
9
  "msw": "^0.39.2",
10
+ "react-query": "^3.34.19"
11
+ },
12
+ "devDependencies": {
10
13
  "orval": "^6.7.1",
11
- "react": "^18.0.0",
12
- "react-query": "^3.34.19",
14
+ "react": "^17.0.0",
13
15
  "typescript": "^4.6.3"
14
16
  },
15
17
  "peerDependencies": {
16
- "@faker-js/faker": "^6.1.2",
17
- "axios": "^0.26.1",
18
- "msw": "^0.39.2",
19
- "orval": "^6.7.1",
20
- "react": "^17.0.2",
21
- "react-query": "^3.34.19"
18
+ "react": "^17.0.0 || ^18.0.0"
22
19
  },
23
20
  "scripts": {
24
21
  "orval": "orval",
25
- "tsToJs": "npx tsc ./src/*",
22
+ "tsToJs": "npx tsc ./dist/*",
26
23
  "build": "yarn orval && yarn tsToJs"
27
24
  }
28
25
  }
@@ -1,17 +1,29 @@
1
- import { faker } from "@faker-js/faker";
2
-
3
1
  export const sites = {
4
2
  limit: 10,
5
3
  n_pages: 1,
6
4
  n_rows: 3,
7
5
  page: 1,
8
- rows: [...Array(3)].map((site, idx) => ({
9
- id: idx,
10
- name: faker.company.companyName(),
11
- url: faker.internet.url(),
12
- })),
6
+ rows: [
7
+ {
8
+ id: "1",
9
+ name: "Bob the Blog",
10
+ url: "https://bobtheblog.com",
11
+ },
12
+ {
13
+ id: "2",
14
+ name: "Wendy the Website",
15
+ url: "https://wendythewebsite.com",
16
+ },
17
+ {
18
+ id: "3",
19
+ name: "Cathy the Coding Camp",
20
+ url: "https://cathythecodingcamp.com",
21
+ },
22
+ ],
13
23
  };
14
24
 
25
+ // TODO: would be nice if we could take in the param (siteId) and return the proper site,
26
+ // but currently we are just dumbly returning the same site regardless of siteId
15
27
  export const site = sites.rows[0];
16
28
 
17
29
  export const siteSso = `${sites.rows[0].url}/wp-login.php?ssotoken=1234567890`;