@atomic-solutions/wordpress-api-client 0.1.0
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/LICENSE +21 -0
- package/README.md +295 -0
- package/dist/calculatePagination-WUlN3OdM.d.cts +19 -0
- package/dist/calculatePagination-WUlN3OdM.d.ts +19 -0
- package/dist/client/index.cjs +1143 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +10 -0
- package/dist/client/index.d.ts +10 -0
- package/dist/client/index.js +1137 -0
- package/dist/client/index.js.map +1 -0
- package/dist/http/index.cjs +674 -0
- package/dist/http/index.cjs.map +1 -0
- package/dist/http/index.d.cts +12 -0
- package/dist/http/index.d.ts +12 -0
- package/dist/http/index.js +667 -0
- package/dist/http/index.js.map +1 -0
- package/dist/index.cjs +1251 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +51 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +1205 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/index.cjs +414 -0
- package/dist/schemas/index.cjs.map +1 -0
- package/dist/schemas/index.d.cts +1339 -0
- package/dist/schemas/index.d.ts +1339 -0
- package/dist/schemas/index.js +376 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/testing/index.cjs +1435 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +50 -0
- package/dist/testing/index.d.ts +50 -0
- package/dist/testing/index.js +1426 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types-8pbwmNdu.d.ts +154 -0
- package/dist/types-BTo088EY.d.cts +154 -0
- package/dist/user.schema-eeUHQ4sI.d.cts +10614 -0
- package/dist/user.schema-eeUHQ4sI.d.ts +10614 -0
- package/dist/utils/index.cjs +47 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +10 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.js +44 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +103 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/calculatePagination.ts
|
|
4
|
+
var calculatePagination = (input) => {
|
|
5
|
+
const { page, perPage, total, totalPages } = input;
|
|
6
|
+
const hasNextPage = page < totalPages;
|
|
7
|
+
const hasPrevPage = page > 1;
|
|
8
|
+
return {
|
|
9
|
+
page,
|
|
10
|
+
perPage,
|
|
11
|
+
total,
|
|
12
|
+
totalPages,
|
|
13
|
+
hasNextPage,
|
|
14
|
+
hasPrevPage,
|
|
15
|
+
nextPage: hasNextPage ? page + 1 : null,
|
|
16
|
+
prevPage: hasPrevPage ? page - 1 : null
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/utils/getPaginationMeta.ts
|
|
21
|
+
var getPaginationMeta = (headers) => {
|
|
22
|
+
if (!headers) {
|
|
23
|
+
return {
|
|
24
|
+
total: 0,
|
|
25
|
+
totalPages: 0
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const wpTotal = headers["x-wp-total"];
|
|
29
|
+
const wpTotalPages = headers["x-wp-totalpages"];
|
|
30
|
+
if (!wpTotal || !wpTotalPages) {
|
|
31
|
+
return {
|
|
32
|
+
total: 0,
|
|
33
|
+
totalPages: 0
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const total = parseInt(wpTotal, 10);
|
|
37
|
+
const totalPages = parseInt(wpTotalPages, 10);
|
|
38
|
+
return {
|
|
39
|
+
total,
|
|
40
|
+
totalPages
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.calculatePagination = calculatePagination;
|
|
45
|
+
exports.getPaginationMeta = getPaginationMeta;
|
|
46
|
+
//# sourceMappingURL=index.cjs.map
|
|
47
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/calculatePagination.ts","../../src/utils/getPaginationMeta.ts"],"names":[],"mappings":";;;AA4BO,IAAM,mBAAA,GAAsB,CAAC,KAAA,KAAgD;AAClF,EAAA,MAAM,EAAE,IAAA,EAAM,OAAA,EAAS,KAAA,EAAO,YAAW,GAAI,KAAA;AAE7C,EAAA,MAAM,cAAc,IAAA,GAAO,UAAA;AAC3B,EAAA,MAAM,cAAc,IAAA,GAAO,CAAA;AAE3B,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA,QAAA,EAAU,WAAA,GAAc,IAAA,GAAO,CAAA,GAAI,IAAA;AAAA,IACnC,QAAA,EAAU,WAAA,GAAc,IAAA,GAAO,CAAA,GAAI;AAAA,GACrC;AACF;;;ACzBO,IAAM,iBAAA,GAAoB,CAAC,OAAA,KAAsD;AAEtF,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,CAAA;AAAA,MACP,UAAA,EAAY;AAAA,KACd;AAAA,EACF;AAEA,EAAA,MAAM,OAAA,GAAU,QAAQ,YAAY,CAAA;AACpC,EAAA,MAAM,YAAA,GAAe,QAAQ,iBAAiB,CAAA;AAE9C,EAAA,IAAI,CAAC,OAAA,IAAW,CAAC,YAAA,EAAc;AAC7B,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,CAAA;AAAA,MACP,UAAA,EAAY;AAAA,KACd;AAAA,EACF;AAEA,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,OAAA,EAAS,EAAE,CAAA;AAClC,EAAA,MAAM,UAAA,GAAa,QAAA,CAAS,YAAA,EAAc,EAAE,CAAA;AAE5C,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["/**\n * Calculate pagination navigation\n */\n\nexport interface Pagination {\n page: number;\n perPage: number;\n total: number;\n totalPages: number;\n hasNextPage: boolean;\n hasPrevPage: boolean;\n nextPage: number | null;\n prevPage: number | null;\n}\n\nexport interface CalculatePaginationInput {\n page: number;\n perPage: number;\n total: number;\n totalPages: number;\n}\n\n/**\n * Calculate pagination navigation from WordPress pagination metadata\n *\n * @param input - Current pagination state\n * @returns Full pagination object with navigation helpers\n */\nexport const calculatePagination = (input: CalculatePaginationInput): Pagination => {\n const { page, perPage, total, totalPages } = input;\n\n const hasNextPage = page < totalPages;\n const hasPrevPage = page > 1;\n\n return {\n page,\n perPage,\n total,\n totalPages,\n hasNextPage,\n hasPrevPage,\n nextPage: hasNextPage ? page + 1 : null,\n prevPage: hasPrevPage ? page - 1 : null,\n };\n};\n","/**\n * Extract pagination metadata from WordPress response headers\n */\n\nimport type { AxiosResponse } from 'axios';\n\nexport interface PaginationMeta {\n total: number;\n totalPages: number;\n}\n\n/**\n * Extract pagination metadata from WordPress REST API headers\n *\n * WordPress uses x-wp-total and x-wp-totalpages headers for pagination\n *\n * @param headers - Axios response headers\n * @returns Pagination metadata object\n */\nexport const getPaginationMeta = (headers: AxiosResponse['headers']): PaginationMeta => {\n // Handle undefined/null headers\n if (!headers) {\n return {\n total: 0,\n totalPages: 0,\n };\n }\n\n const wpTotal = headers['x-wp-total'];\n const wpTotalPages = headers['x-wp-totalpages'];\n\n if (!wpTotal || !wpTotalPages) {\n return {\n total: 0,\n totalPages: 0,\n };\n }\n\n const total = parseInt(wpTotal, 10);\n const totalPages = parseInt(wpTotalPages, 10);\n\n return {\n total,\n totalPages,\n };\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { P as Pagination, c as calculatePagination } from '../calculatePagination-WUlN3OdM.cjs';
|
|
2
|
+
import { AxiosResponse } from 'axios';
|
|
3
|
+
|
|
4
|
+
interface PaginationMeta {
|
|
5
|
+
total: number;
|
|
6
|
+
totalPages: number;
|
|
7
|
+
}
|
|
8
|
+
declare const getPaginationMeta: (headers: AxiosResponse["headers"]) => PaginationMeta;
|
|
9
|
+
|
|
10
|
+
export { type PaginationMeta, getPaginationMeta };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { P as Pagination, c as calculatePagination } from '../calculatePagination-WUlN3OdM.js';
|
|
2
|
+
import { AxiosResponse } from 'axios';
|
|
3
|
+
|
|
4
|
+
interface PaginationMeta {
|
|
5
|
+
total: number;
|
|
6
|
+
totalPages: number;
|
|
7
|
+
}
|
|
8
|
+
declare const getPaginationMeta: (headers: AxiosResponse["headers"]) => PaginationMeta;
|
|
9
|
+
|
|
10
|
+
export { type PaginationMeta, getPaginationMeta };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/utils/calculatePagination.ts
|
|
2
|
+
var calculatePagination = (input) => {
|
|
3
|
+
const { page, perPage, total, totalPages } = input;
|
|
4
|
+
const hasNextPage = page < totalPages;
|
|
5
|
+
const hasPrevPage = page > 1;
|
|
6
|
+
return {
|
|
7
|
+
page,
|
|
8
|
+
perPage,
|
|
9
|
+
total,
|
|
10
|
+
totalPages,
|
|
11
|
+
hasNextPage,
|
|
12
|
+
hasPrevPage,
|
|
13
|
+
nextPage: hasNextPage ? page + 1 : null,
|
|
14
|
+
prevPage: hasPrevPage ? page - 1 : null
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/utils/getPaginationMeta.ts
|
|
19
|
+
var getPaginationMeta = (headers) => {
|
|
20
|
+
if (!headers) {
|
|
21
|
+
return {
|
|
22
|
+
total: 0,
|
|
23
|
+
totalPages: 0
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const wpTotal = headers["x-wp-total"];
|
|
27
|
+
const wpTotalPages = headers["x-wp-totalpages"];
|
|
28
|
+
if (!wpTotal || !wpTotalPages) {
|
|
29
|
+
return {
|
|
30
|
+
total: 0,
|
|
31
|
+
totalPages: 0
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const total = parseInt(wpTotal, 10);
|
|
35
|
+
const totalPages = parseInt(wpTotalPages, 10);
|
|
36
|
+
return {
|
|
37
|
+
total,
|
|
38
|
+
totalPages
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { calculatePagination, getPaginationMeta };
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/calculatePagination.ts","../../src/utils/getPaginationMeta.ts"],"names":[],"mappings":";AA4BO,IAAM,mBAAA,GAAsB,CAAC,KAAA,KAAgD;AAClF,EAAA,MAAM,EAAE,IAAA,EAAM,OAAA,EAAS,KAAA,EAAO,YAAW,GAAI,KAAA;AAE7C,EAAA,MAAM,cAAc,IAAA,GAAO,UAAA;AAC3B,EAAA,MAAM,cAAc,IAAA,GAAO,CAAA;AAE3B,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA,QAAA,EAAU,WAAA,GAAc,IAAA,GAAO,CAAA,GAAI,IAAA;AAAA,IACnC,QAAA,EAAU,WAAA,GAAc,IAAA,GAAO,CAAA,GAAI;AAAA,GACrC;AACF;;;ACzBO,IAAM,iBAAA,GAAoB,CAAC,OAAA,KAAsD;AAEtF,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,CAAA;AAAA,MACP,UAAA,EAAY;AAAA,KACd;AAAA,EACF;AAEA,EAAA,MAAM,OAAA,GAAU,QAAQ,YAAY,CAAA;AACpC,EAAA,MAAM,YAAA,GAAe,QAAQ,iBAAiB,CAAA;AAE9C,EAAA,IAAI,CAAC,OAAA,IAAW,CAAC,YAAA,EAAc;AAC7B,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,CAAA;AAAA,MACP,UAAA,EAAY;AAAA,KACd;AAAA,EACF;AAEA,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,OAAA,EAAS,EAAE,CAAA;AAClC,EAAA,MAAM,UAAA,GAAa,QAAA,CAAS,YAAA,EAAc,EAAE,CAAA;AAE5C,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * Calculate pagination navigation\n */\n\nexport interface Pagination {\n page: number;\n perPage: number;\n total: number;\n totalPages: number;\n hasNextPage: boolean;\n hasPrevPage: boolean;\n nextPage: number | null;\n prevPage: number | null;\n}\n\nexport interface CalculatePaginationInput {\n page: number;\n perPage: number;\n total: number;\n totalPages: number;\n}\n\n/**\n * Calculate pagination navigation from WordPress pagination metadata\n *\n * @param input - Current pagination state\n * @returns Full pagination object with navigation helpers\n */\nexport const calculatePagination = (input: CalculatePaginationInput): Pagination => {\n const { page, perPage, total, totalPages } = input;\n\n const hasNextPage = page < totalPages;\n const hasPrevPage = page > 1;\n\n return {\n page,\n perPage,\n total,\n totalPages,\n hasNextPage,\n hasPrevPage,\n nextPage: hasNextPage ? page + 1 : null,\n prevPage: hasPrevPage ? page - 1 : null,\n };\n};\n","/**\n * Extract pagination metadata from WordPress response headers\n */\n\nimport type { AxiosResponse } from 'axios';\n\nexport interface PaginationMeta {\n total: number;\n totalPages: number;\n}\n\n/**\n * Extract pagination metadata from WordPress REST API headers\n *\n * WordPress uses x-wp-total and x-wp-totalpages headers for pagination\n *\n * @param headers - Axios response headers\n * @returns Pagination metadata object\n */\nexport const getPaginationMeta = (headers: AxiosResponse['headers']): PaginationMeta => {\n // Handle undefined/null headers\n if (!headers) {\n return {\n total: 0,\n totalPages: 0,\n };\n }\n\n const wpTotal = headers['x-wp-total'];\n const wpTotalPages = headers['x-wp-totalpages'];\n\n if (!wpTotal || !wpTotalPages) {\n return {\n total: 0,\n totalPages: 0,\n };\n }\n\n const total = parseInt(wpTotal, 10);\n const totalPages = parseInt(wpTotalPages, 10);\n\n return {\n total,\n totalPages,\n };\n};\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atomic-solutions/wordpress-api-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Type-safe WordPress REST API client (platform-agnostic)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./client": {
|
|
15
|
+
"types": "./dist/client/index.d.ts",
|
|
16
|
+
"import": "./dist/client/index.js",
|
|
17
|
+
"require": "./dist/client/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./schemas": {
|
|
20
|
+
"types": "./dist/schemas/index.d.ts",
|
|
21
|
+
"import": "./dist/schemas/index.js",
|
|
22
|
+
"require": "./dist/schemas/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./http": {
|
|
25
|
+
"types": "./dist/http/index.d.ts",
|
|
26
|
+
"import": "./dist/http/index.js",
|
|
27
|
+
"require": "./dist/http/index.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./utils": {
|
|
30
|
+
"types": "./dist/utils/index.d.ts",
|
|
31
|
+
"import": "./dist/utils/index.js",
|
|
32
|
+
"require": "./dist/utils/index.cjs"
|
|
33
|
+
},
|
|
34
|
+
"./testing": {
|
|
35
|
+
"types": "./dist/testing/index.d.ts",
|
|
36
|
+
"import": "./dist/testing/index.js",
|
|
37
|
+
"require": "./dist/testing/index.cjs"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"README.md",
|
|
43
|
+
"dist",
|
|
44
|
+
"LICENSE"
|
|
45
|
+
],
|
|
46
|
+
"keywords": [
|
|
47
|
+
"wordpress",
|
|
48
|
+
"rest-api",
|
|
49
|
+
"wp-json",
|
|
50
|
+
"typescript",
|
|
51
|
+
"platform-agnostic",
|
|
52
|
+
"client",
|
|
53
|
+
"api-client"
|
|
54
|
+
],
|
|
55
|
+
"author": "Atomic Solutions",
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "https://github.com/atomic-solutions/wordpress-woocommerce-monorepo",
|
|
60
|
+
"directory": "packages/wordpress-utils"
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"axios": ">=1.7.0",
|
|
67
|
+
"zod": ">=3.0.0"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@eslint/compat": "^1.3.2",
|
|
71
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
72
|
+
"@eslint/js": "^9.35.0",
|
|
73
|
+
"@types/node": "^24.10.1",
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^8.48.0",
|
|
75
|
+
"@vitest/coverage-v8": "^2.0.0",
|
|
76
|
+
"axios": "^1.7.7",
|
|
77
|
+
"axios-mock-adapter": "^2.1.0",
|
|
78
|
+
"eslint": "^9.35.0",
|
|
79
|
+
"eslint-config-prettier": "^10.1.8",
|
|
80
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
81
|
+
"prettier": "^3.0.0",
|
|
82
|
+
"release-it": "^19.0.6",
|
|
83
|
+
"tsup": "^8.0.0",
|
|
84
|
+
"tsx": "^4.20.6",
|
|
85
|
+
"typescript": "^5.9.0",
|
|
86
|
+
"vitest": "^2.0.0",
|
|
87
|
+
"zod": "^3.23.0"
|
|
88
|
+
},
|
|
89
|
+
"sideEffects": false,
|
|
90
|
+
"scripts": {
|
|
91
|
+
"build": "tsup",
|
|
92
|
+
"dev": "tsup --watch",
|
|
93
|
+
"typecheck": "tsc --noEmit",
|
|
94
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
95
|
+
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
96
|
+
"test": "vitest run --exclude '**/wordpress-api.integration.test.ts' --passWithNoTests",
|
|
97
|
+
"test:integration": "vitest run tests/integration/wordpress-api.integration.test.ts",
|
|
98
|
+
"test:all": "vitest run",
|
|
99
|
+
"test:watch": "vitest",
|
|
100
|
+
"test:coverage": "vitest run --coverage --exclude '**/wordpress-api.integration.test.ts'",
|
|
101
|
+
"clean": "rm -rf dist"
|
|
102
|
+
}
|
|
103
|
+
}
|