Compare commits
No commits in common. "master" and "v1.0.5" have entirely different histories.
15
changelog.md
15
changelog.md
@ -1,20 +1,5 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 2024-07-02 - 1.0.7 - fix(metadata)
|
|
||||||
Update project metadata and readme for new scope and descriptions
|
|
||||||
|
|
||||||
- Updated package name and description in package.json
|
|
||||||
- Updated repository and scope information in npmextra.json
|
|
||||||
- Expanded readme with detailed usage instructions and examples
|
|
||||||
|
|
||||||
## 2024-07-01 - 1.0.6 - fix(medium)
|
|
||||||
Fix various bugs and improve async handling.
|
|
||||||
|
|
||||||
- Update @push.rocks/qenv dependency to ^6.0.5
|
|
||||||
- Fix bug in test: await getEnvVarOnDemand
|
|
||||||
- Improve error handling in getAccountInfo
|
|
||||||
- Simplify fetching publications by refactoring methods in MediumPublication and MediumAccount classes
|
|
||||||
|
|
||||||
## 2024-07-01 - 1.0.5 - fix(core)
|
## 2024-07-01 - 1.0.5 - fix(core)
|
||||||
Fixed module name inconsistencies and documentation links
|
Fixed module name inconsistencies and documentation links
|
||||||
|
|
||||||
|
@ -2,30 +2,13 @@
|
|||||||
"gitzone": {
|
"gitzone": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "code.foss.global",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "apiclient.xyz",
|
"gitscope": "mojoio",
|
||||||
"gitrepo": "medium",
|
"gitrepo": "medium",
|
||||||
"shortDescription": "an unofficial medium.com API package",
|
"shortDescription": "an unofficial medium.com API package",
|
||||||
"npmPackagename": "@apiclient.xyz/medium",
|
"npmPackagename": "@push.rocks/medium",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "apiclient.xyz",
|
"projectDomain": "mojo.io"
|
||||||
"description": "An unofficial Medium.com API package that enables interaction with Medium's features using Node.js.",
|
|
||||||
"keywords": [
|
|
||||||
"Medium",
|
|
||||||
"API",
|
|
||||||
"Medium API",
|
|
||||||
"unofficial",
|
|
||||||
"Node.js",
|
|
||||||
"TypeScript",
|
|
||||||
"publications",
|
|
||||||
"posts",
|
|
||||||
"account management",
|
|
||||||
"automation",
|
|
||||||
"JavaScript",
|
|
||||||
"blogging",
|
|
||||||
"content creation",
|
|
||||||
"web development"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/medium",
|
"name": "@mojoio/medium",
|
||||||
"version": "1.0.7",
|
"version": "1.0.5",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
24
package.json
24
package.json
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiclient.xyz/medium",
|
"name": "@mojoio/medium",
|
||||||
"version": "1.0.7",
|
"version": "1.0.5",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "An unofficial Medium.com API package that enables interaction with Medium's features using Node.js.",
|
"description": "an unofficial medium.com API package",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@ -21,7 +21,7 @@
|
|||||||
"@types/node": "^20.14.9"
|
"@types/node": "^20.14.9"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/qenv": "^6.0.5",
|
"@push.rocks/qenv": "^5.0.2",
|
||||||
"@push.rocks/smartpromise": "^4.0.2",
|
"@push.rocks/smartpromise": "^4.0.2",
|
||||||
"@push.rocks/smartrequest": "^2.0.15"
|
"@push.rocks/smartrequest": "^2.0.15"
|
||||||
},
|
},
|
||||||
@ -39,21 +39,5 @@
|
|||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
|
||||||
"keywords": [
|
|
||||||
"Medium",
|
|
||||||
"API",
|
|
||||||
"Medium API",
|
|
||||||
"unofficial",
|
|
||||||
"Node.js",
|
|
||||||
"TypeScript",
|
|
||||||
"publications",
|
|
||||||
"posts",
|
|
||||||
"account management",
|
|
||||||
"automation",
|
|
||||||
"JavaScript",
|
|
||||||
"blogging",
|
|
||||||
"content creation",
|
|
||||||
"web development"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
110
pnpm-lock.yaml
generated
110
pnpm-lock.yaml
generated
@ -9,8 +9,8 @@ importers:
|
|||||||
.:
|
.:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@push.rocks/qenv':
|
'@push.rocks/qenv':
|
||||||
specifier: ^6.0.5
|
specifier: ^5.0.2
|
||||||
version: 6.0.5
|
version: 5.0.5
|
||||||
'@push.rocks/smartpromise':
|
'@push.rocks/smartpromise':
|
||||||
specifier: ^4.0.2
|
specifier: ^4.0.2
|
||||||
version: 4.0.4
|
version: 4.0.4
|
||||||
@ -334,8 +334,8 @@ packages:
|
|||||||
'@push.rocks/lik@6.0.15':
|
'@push.rocks/lik@6.0.15':
|
||||||
resolution: {integrity: sha512-rZxln6l4NAU931MTxnsjy1pue+S3AXtDCidHH/tbkqBtrWIzWuXduo6Nz3zYkndbD64Knyta7F60JRvcOe4XqA==}
|
resolution: {integrity: sha512-rZxln6l4NAU931MTxnsjy1pue+S3AXtDCidHH/tbkqBtrWIzWuXduo6Nz3zYkndbD64Knyta7F60JRvcOe4XqA==}
|
||||||
|
|
||||||
'@push.rocks/qenv@6.0.5':
|
'@push.rocks/qenv@5.0.5':
|
||||||
resolution: {integrity: sha512-Id/eSKKqSDUGe+0Cp5HEJ58J1iVv1jQseLUMs9kFTPYwG+NJSETUCRsJV50w5cPv8bRFcSkSU+xVbUbOc1p29A==}
|
resolution: {integrity: sha512-AUmhbXmi3cHUfpXf7Bb7FmPMZ9d+/mRL1brjR4juGIsOubbpTv52Vv+1VlcRlsuyN7sWNvDEpP/Y8SfoOZzYzg==}
|
||||||
|
|
||||||
'@push.rocks/smartbrowser@2.0.6':
|
'@push.rocks/smartbrowser@2.0.6':
|
||||||
resolution: {integrity: sha512-Ne+KCVhV/DROc1rHRRw59K6h0+LpQAK9fdOUtgDZ7laLPmB/tmnbUh3IuRDNcIY1iVA9pydoobwjnTjVgio9eQ==}
|
resolution: {integrity: sha512-Ne+KCVhV/DROc1rHRRw59K6h0+LpQAK9fdOUtgDZ7laLPmB/tmnbUh3IuRDNcIY1iVA9pydoobwjnTjVgio9eQ==}
|
||||||
@ -370,6 +370,9 @@ packages:
|
|||||||
'@push.rocks/smartfile-interfaces@1.0.7':
|
'@push.rocks/smartfile-interfaces@1.0.7':
|
||||||
resolution: {integrity: sha512-MeOl/200UOvSO4Pgq/DVFiBVZpL9gjOBQM+4XYNjSxda8c6VBvchHAntaFLQUlO8U1ckNaP9i+nMO4O4/0ymyw==}
|
resolution: {integrity: sha512-MeOl/200UOvSO4Pgq/DVFiBVZpL9gjOBQM+4XYNjSxda8c6VBvchHAntaFLQUlO8U1ckNaP9i+nMO4O4/0ymyw==}
|
||||||
|
|
||||||
|
'@push.rocks/smartfile@10.0.41':
|
||||||
|
resolution: {integrity: sha512-xOOy0duI34M2qrJZggpk51EHGXmg9+mBL1Q55tNiQKXzfx89P3coY1EAZG8tvmep3qB712QEKe7T+u04t42Kjg==}
|
||||||
|
|
||||||
'@push.rocks/smartfile@11.0.21':
|
'@push.rocks/smartfile@11.0.21':
|
||||||
resolution: {integrity: sha512-ZtF8QPGeR/2MJxtHgJY1+FLrOZ+GTLWqwyDz7Woq1x+K9nb4almA1OpdW5IQPBK3ECHur0ghg5bzzKMuR5ZSzg==}
|
resolution: {integrity: sha512-ZtF8QPGeR/2MJxtHgJY1+FLrOZ+GTLWqwyDz7Woq1x+K9nb4almA1OpdW5IQPBK3ECHur0ghg5bzzKMuR5ZSzg==}
|
||||||
|
|
||||||
@ -403,6 +406,9 @@ packages:
|
|||||||
'@push.rocks/smartmatch@2.0.0':
|
'@push.rocks/smartmatch@2.0.0':
|
||||||
resolution: {integrity: sha512-MBzP++1yNIBeox71X6VxpIgZ8m4bXnJpZJ4nWVH6IWpmO38MXTu4X0QF8tQnyT4LFcwvc9iiWaD15cstHa7Mmw==}
|
resolution: {integrity: sha512-MBzP++1yNIBeox71X6VxpIgZ8m4bXnJpZJ4nWVH6IWpmO38MXTu4X0QF8tQnyT4LFcwvc9iiWaD15cstHa7Mmw==}
|
||||||
|
|
||||||
|
'@push.rocks/smartmime@1.0.6':
|
||||||
|
resolution: {integrity: sha512-PHd+I4UcsnOATNg8wjDsSAmmJ4CwQFrQCNzd0HSJMs4ZpiK3Ya91almd6GLpDPU370U4HFh4FaPF4eEAI6vkJQ==}
|
||||||
|
|
||||||
'@push.rocks/smartmime@2.0.2':
|
'@push.rocks/smartmime@2.0.2':
|
||||||
resolution: {integrity: sha512-aXH1sFD73q9cEwPdeSeN7Zxd2aoVt9wE97ILFCW5gORylvm85Hgfq7SYkqykjQzEL8IDJKJF3G78+xcL2rALTg==}
|
resolution: {integrity: sha512-aXH1sFD73q9cEwPdeSeN7Zxd2aoVt9wE97ILFCW5gORylvm85Hgfq7SYkqykjQzEL8IDJKJF3G78+xcL2rALTg==}
|
||||||
|
|
||||||
@ -454,6 +460,9 @@ packages:
|
|||||||
'@push.rocks/smartstate@2.0.17':
|
'@push.rocks/smartstate@2.0.17':
|
||||||
resolution: {integrity: sha512-ucx0zq8gWL3MuN4ogibUiGJlEH0of9WyDfxu+4pQySEdaZBJw0/UFkBM8wButkj0dF8w4wsVMN4YwZAdVqsAXg==}
|
resolution: {integrity: sha512-ucx0zq8gWL3MuN4ogibUiGJlEH0of9WyDfxu+4pQySEdaZBJw0/UFkBM8wButkj0dF8w4wsVMN4YwZAdVqsAXg==}
|
||||||
|
|
||||||
|
'@push.rocks/smartstream@2.0.8':
|
||||||
|
resolution: {integrity: sha512-GlF/9cCkvBHwKa3DK4DO5wjfSgqkj6gAS4TrY9uD5NMHu9RQv4WiNrElTYj7iCEpnZgUnLO3tzw1JA3NRIMnnA==}
|
||||||
|
|
||||||
'@push.rocks/smartstream@3.0.44':
|
'@push.rocks/smartstream@3.0.44':
|
||||||
resolution: {integrity: sha512-BZwSUmhVD/CEzRdG/e2UachlyNjshiknqBnwHzIFPIjVKC66UgWX5lYCs2LOwJtuUEpfL1vTMOAYUFNcmPjW9A==}
|
resolution: {integrity: sha512-BZwSUmhVD/CEzRdG/e2UachlyNjshiknqBnwHzIFPIjVKC66UgWX5lYCs2LOwJtuUEpfL1vTMOAYUFNcmPjW9A==}
|
||||||
|
|
||||||
@ -676,6 +685,9 @@ packages:
|
|||||||
'@types/express@4.17.21':
|
'@types/express@4.17.21':
|
||||||
resolution: {integrity: sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ==}
|
resolution: {integrity: sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ==}
|
||||||
|
|
||||||
|
'@types/from2@2.3.5':
|
||||||
|
resolution: {integrity: sha512-giavnjf3kNlJnE+HpZA1CQ3UKHxgehzsTuIMGda8pGMbOiLYGVNADEskey44OZcADHm/HOoBany8IV+0x28XFw==}
|
||||||
|
|
||||||
'@types/fs-extra@11.0.4':
|
'@types/fs-extra@11.0.4':
|
||||||
resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==}
|
resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==}
|
||||||
|
|
||||||
@ -1113,6 +1125,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-TG2hpqe4ELx54QER/S3HQ9SRVnQnGBtKUz5bLQWtYAQ+o6GpgMs6sYUvaiJjVxb+UXwhRhAEP3m7LbsIZ77Hmw==}
|
resolution: {integrity: sha512-TG2hpqe4ELx54QER/S3HQ9SRVnQnGBtKUz5bLQWtYAQ+o6GpgMs6sYUvaiJjVxb+UXwhRhAEP3m7LbsIZ77Hmw==}
|
||||||
engines: {node: '>= 0.8'}
|
engines: {node: '>= 0.8'}
|
||||||
|
|
||||||
|
core-util-is@1.0.3:
|
||||||
|
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
|
||||||
|
|
||||||
cors@2.8.5:
|
cors@2.8.5:
|
||||||
resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==}
|
resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==}
|
||||||
engines: {node: '>= 0.10'}
|
engines: {node: '>= 0.10'}
|
||||||
@ -1459,6 +1474,9 @@ packages:
|
|||||||
resolution: {integrity: sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=}
|
resolution: {integrity: sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=}
|
||||||
engines: {node: '>= 0.6'}
|
engines: {node: '>= 0.6'}
|
||||||
|
|
||||||
|
from2@2.3.0:
|
||||||
|
resolution: {integrity: sha1-i/tVAr3kpNNs/e6gB/zKIdfjgq8=}
|
||||||
|
|
||||||
fs-constants@1.0.0:
|
fs-constants@1.0.0:
|
||||||
resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==}
|
resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==}
|
||||||
|
|
||||||
@ -1739,6 +1757,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==}
|
resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
|
||||||
|
isarray@1.0.0:
|
||||||
|
resolution: {integrity: sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=}
|
||||||
|
|
||||||
isbinaryfile@5.0.2:
|
isbinaryfile@5.0.2:
|
||||||
resolution: {integrity: sha512-GvcjojwonMjWbTkfMpnVHVqXW/wKMYDfEpY94/8zy8HFMOqb/VL6oeONq9v87q4ttVlaTLnGXnJD4B5B1OTGIg==}
|
resolution: {integrity: sha512-GvcjojwonMjWbTkfMpnVHVqXW/wKMYDfEpY94/8zy8HFMOqb/VL6oeONq9v87q4ttVlaTLnGXnJD4B5B1OTGIg==}
|
||||||
engines: {node: '>= 18.0.0'}
|
engines: {node: '>= 18.0.0'}
|
||||||
@ -2357,6 +2378,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-ASJqOugUF1bbzI35STMBUpZqdfYKlJugy6JBziGi2EE+AL5JPJGSzvpeVXojxrr0ViUYoToUjb5kjSEGf7Y83Q==}
|
resolution: {integrity: sha512-ASJqOugUF1bbzI35STMBUpZqdfYKlJugy6JBziGi2EE+AL5JPJGSzvpeVXojxrr0ViUYoToUjb5kjSEGf7Y83Q==}
|
||||||
engines: {node: '>=14.16'}
|
engines: {node: '>=14.16'}
|
||||||
|
|
||||||
|
process-nextick-args@2.0.1:
|
||||||
|
resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
|
||||||
|
|
||||||
progress@2.0.3:
|
progress@2.0.3:
|
||||||
resolution: {integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==}
|
resolution: {integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==}
|
||||||
engines: {node: '>=0.4.0'}
|
engines: {node: '>=0.4.0'}
|
||||||
@ -2419,6 +2443,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==}
|
resolution: {integrity: sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==}
|
||||||
engines: {node: '>= 0.8'}
|
engines: {node: '>= 0.8'}
|
||||||
|
|
||||||
|
readable-stream@2.3.8:
|
||||||
|
resolution: {integrity: sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==}
|
||||||
|
|
||||||
readable-stream@3.6.2:
|
readable-stream@3.6.2:
|
||||||
resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==}
|
resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==}
|
||||||
engines: {node: '>= 6'}
|
engines: {node: '>= 6'}
|
||||||
@ -2492,6 +2519,9 @@ packages:
|
|||||||
rxjs@7.8.1:
|
rxjs@7.8.1:
|
||||||
resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==}
|
resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==}
|
||||||
|
|
||||||
|
safe-buffer@5.1.2:
|
||||||
|
resolution: {integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==}
|
||||||
|
|
||||||
safe-buffer@5.2.1:
|
safe-buffer@5.2.1:
|
||||||
resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
|
resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
|
||||||
|
|
||||||
@ -2604,6 +2634,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==}
|
resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
|
|
||||||
|
string_decoder@1.1.1:
|
||||||
|
resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==}
|
||||||
|
|
||||||
string_decoder@1.3.0:
|
string_decoder@1.3.0:
|
||||||
resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}
|
resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}
|
||||||
|
|
||||||
@ -3399,11 +3432,10 @@ snapshots:
|
|||||||
'@types/symbol-tree': 3.2.5
|
'@types/symbol-tree': 3.2.5
|
||||||
symbol-tree: 3.2.4
|
symbol-tree: 3.2.4
|
||||||
|
|
||||||
'@push.rocks/qenv@6.0.5':
|
'@push.rocks/qenv@5.0.5':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@api.global/typedrequest': 3.0.30
|
|
||||||
'@configvault.io/interfaces': 1.0.17
|
'@configvault.io/interfaces': 1.0.17
|
||||||
'@push.rocks/smartfile': 11.0.21
|
'@push.rocks/smartfile': 10.0.41
|
||||||
'@push.rocks/smartlog': 3.0.7
|
'@push.rocks/smartlog': 3.0.7
|
||||||
'@push.rocks/smartpath': 5.0.18
|
'@push.rocks/smartpath': 5.0.18
|
||||||
|
|
||||||
@ -3476,6 +3508,25 @@ snapshots:
|
|||||||
|
|
||||||
'@push.rocks/smartfile-interfaces@1.0.7': {}
|
'@push.rocks/smartfile-interfaces@1.0.7': {}
|
||||||
|
|
||||||
|
'@push.rocks/smartfile@10.0.41':
|
||||||
|
dependencies:
|
||||||
|
'@push.rocks/lik': 6.0.15
|
||||||
|
'@push.rocks/smartdelay': 3.0.5
|
||||||
|
'@push.rocks/smartfile-interfaces': 1.0.7
|
||||||
|
'@push.rocks/smarthash': 3.0.4
|
||||||
|
'@push.rocks/smartjson': 5.0.20
|
||||||
|
'@push.rocks/smartmime': 1.0.6
|
||||||
|
'@push.rocks/smartpath': 5.0.18
|
||||||
|
'@push.rocks/smartpromise': 4.0.4
|
||||||
|
'@push.rocks/smartrequest': 2.0.22
|
||||||
|
'@push.rocks/smartstream': 2.0.8
|
||||||
|
'@types/fs-extra': 11.0.4
|
||||||
|
'@types/glob': 8.1.0
|
||||||
|
'@types/js-yaml': 4.0.9
|
||||||
|
fs-extra: 11.2.0
|
||||||
|
glob: 10.4.2
|
||||||
|
js-yaml: 4.1.0
|
||||||
|
|
||||||
'@push.rocks/smartfile@11.0.21':
|
'@push.rocks/smartfile@11.0.21':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@push.rocks/lik': 6.0.15
|
'@push.rocks/lik': 6.0.15
|
||||||
@ -3555,6 +3606,11 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
matcher: 5.0.0
|
matcher: 5.0.0
|
||||||
|
|
||||||
|
'@push.rocks/smartmime@1.0.6':
|
||||||
|
dependencies:
|
||||||
|
'@types/mime-types': 2.1.4
|
||||||
|
mime-types: 2.1.35
|
||||||
|
|
||||||
'@push.rocks/smartmime@2.0.2':
|
'@push.rocks/smartmime@2.0.2':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/mime-types': 2.1.4
|
'@types/mime-types': 2.1.4
|
||||||
@ -3703,6 +3759,15 @@ snapshots:
|
|||||||
'@push.rocks/smartrx': 3.0.7
|
'@push.rocks/smartrx': 3.0.7
|
||||||
'@push.rocks/webstore': 2.0.20
|
'@push.rocks/webstore': 2.0.20
|
||||||
|
|
||||||
|
'@push.rocks/smartstream@2.0.8':
|
||||||
|
dependencies:
|
||||||
|
'@push.rocks/smartpromise': 4.0.4
|
||||||
|
'@push.rocks/smartrx': 3.0.7
|
||||||
|
'@types/from2': 2.3.5
|
||||||
|
'@types/through2': 2.0.41
|
||||||
|
from2: 2.3.0
|
||||||
|
through2: 4.0.2
|
||||||
|
|
||||||
'@push.rocks/smartstream@3.0.44':
|
'@push.rocks/smartstream@3.0.44':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@push.rocks/lik': 6.0.15
|
'@push.rocks/lik': 6.0.15
|
||||||
@ -4045,6 +4110,10 @@ snapshots:
|
|||||||
'@types/qs': 6.9.15
|
'@types/qs': 6.9.15
|
||||||
'@types/serve-static': 1.15.7
|
'@types/serve-static': 1.15.7
|
||||||
|
|
||||||
|
'@types/from2@2.3.5':
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 20.14.9
|
||||||
|
|
||||||
'@types/fs-extra@11.0.4':
|
'@types/fs-extra@11.0.4':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/jsonfile': 6.1.4
|
'@types/jsonfile': 6.1.4
|
||||||
@ -4546,6 +4615,8 @@ snapshots:
|
|||||||
depd: 2.0.0
|
depd: 2.0.0
|
||||||
keygrip: 1.1.0
|
keygrip: 1.1.0
|
||||||
|
|
||||||
|
core-util-is@1.0.3: {}
|
||||||
|
|
||||||
cors@2.8.5:
|
cors@2.8.5:
|
||||||
dependencies:
|
dependencies:
|
||||||
object-assign: 4.1.1
|
object-assign: 4.1.1
|
||||||
@ -4928,6 +4999,11 @@ snapshots:
|
|||||||
|
|
||||||
fresh@0.5.2: {}
|
fresh@0.5.2: {}
|
||||||
|
|
||||||
|
from2@2.3.0:
|
||||||
|
dependencies:
|
||||||
|
inherits: 2.0.4
|
||||||
|
readable-stream: 2.3.8
|
||||||
|
|
||||||
fs-constants@1.0.0: {}
|
fs-constants@1.0.0: {}
|
||||||
|
|
||||||
fs-extra@11.2.0:
|
fs-extra@11.2.0:
|
||||||
@ -5274,6 +5350,8 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
is-docker: 2.2.1
|
is-docker: 2.2.1
|
||||||
|
|
||||||
|
isarray@1.0.0: {}
|
||||||
|
|
||||||
isbinaryfile@5.0.2: {}
|
isbinaryfile@5.0.2: {}
|
||||||
|
|
||||||
isexe@2.0.0: {}
|
isexe@2.0.0: {}
|
||||||
@ -6045,6 +6123,8 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
parse-ms: 3.0.0
|
parse-ms: 3.0.0
|
||||||
|
|
||||||
|
process-nextick-args@2.0.1: {}
|
||||||
|
|
||||||
progress@2.0.3: {}
|
progress@2.0.3: {}
|
||||||
|
|
||||||
property-information@6.5.0: {}
|
property-information@6.5.0: {}
|
||||||
@ -6121,6 +6201,16 @@ snapshots:
|
|||||||
iconv-lite: 0.4.24
|
iconv-lite: 0.4.24
|
||||||
unpipe: 1.0.0
|
unpipe: 1.0.0
|
||||||
|
|
||||||
|
readable-stream@2.3.8:
|
||||||
|
dependencies:
|
||||||
|
core-util-is: 1.0.3
|
||||||
|
inherits: 2.0.4
|
||||||
|
isarray: 1.0.0
|
||||||
|
process-nextick-args: 2.0.1
|
||||||
|
safe-buffer: 5.1.2
|
||||||
|
string_decoder: 1.1.1
|
||||||
|
util-deprecate: 1.0.2
|
||||||
|
|
||||||
readable-stream@3.6.2:
|
readable-stream@3.6.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
inherits: 2.0.4
|
inherits: 2.0.4
|
||||||
@ -6225,6 +6315,8 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.6.3
|
tslib: 2.6.3
|
||||||
|
|
||||||
|
safe-buffer@5.1.2: {}
|
||||||
|
|
||||||
safe-buffer@5.2.1: {}
|
safe-buffer@5.2.1: {}
|
||||||
|
|
||||||
safer-buffer@2.1.2: {}
|
safer-buffer@2.1.2: {}
|
||||||
@ -6374,6 +6466,10 @@ snapshots:
|
|||||||
emoji-regex: 9.2.2
|
emoji-regex: 9.2.2
|
||||||
strip-ansi: 7.1.0
|
strip-ansi: 7.1.0
|
||||||
|
|
||||||
|
string_decoder@1.1.1:
|
||||||
|
dependencies:
|
||||||
|
safe-buffer: 5.1.2
|
||||||
|
|
||||||
string_decoder@1.3.0:
|
string_decoder@1.3.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
safe-buffer: 5.2.1
|
safe-buffer: 5.2.1
|
||||||
|
261
readme.md
261
readme.md
@ -1,244 +1,39 @@
|
|||||||
# @apiclient.xyz/medium
|
# @mojoio/medium
|
||||||
|
an unofficial medium.com API package
|
||||||
|
|
||||||
An unofficial Medium.com API package that allows interaction with Medium's features using Node.js.
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/medium)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/mojoio/medium)
|
||||||
|
* [github.com (source mirror)](https://github.com/mojoio/medium)
|
||||||
|
* [docs (typedoc)](https://mojoio.gitlab.io/medium/)
|
||||||
|
|
||||||
## Install
|
## Status for master
|
||||||
|
|
||||||
To install the `@apiclient.xyz/medium` package, ensure you have Node.js and npm installed on your system. Then, run the following command in your terminal:
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
```bash
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
npm install @apiclient.xyz/medium
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
```
|
npm | [](https://lossless.cloud)
|
||||||
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
This guide will walk you through how to use the `@apiclient.xyz/medium` package to interact with the Medium API. This includes steps to initialize your Medium account, retrieve account and publication information, and create new posts. The examples will use ESM syntax and TypeScript to ensure you have the best experience with code intelligence and type safety.
|
Use TypeScript for best in class intellisense
|
||||||
|
|
||||||
### 1. Importing Required Classes
|
## Contribution
|
||||||
|
|
||||||
Start by importing the necessary classes from the `@apiclient.xyz/medium` package.
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
```typescript
|
For further information read the linked docs at the top of this readme.
|
||||||
import { MediumAccount, MediumPublication, MediumPost, IPostData } from '@apiclient.xyz/medium';
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Initializing a Medium Account
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
To use the Medium API, you'll need to initialize a `MediumAccount` object with your access token.
|
[](https://maintainedby.lossless.com)
|
||||||
|
|
||||||
```typescript
|
|
||||||
const mediumAccount = new MediumAccount('YOUR_ACCESS_TOKEN_HERE');
|
|
||||||
|
|
||||||
// Wait for the account to be ready
|
|
||||||
await mediumAccount.readyDeferred.promise;
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Fetching Account Information
|
|
||||||
|
|
||||||
Retrieve account information such as ID, username, URL, and image URL.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const accountInfo = await mediumAccount.getAccountInfo();
|
|
||||||
console.log(accountInfo);
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. Working with Publications
|
|
||||||
|
|
||||||
You can interact with publications associated with your account by fetching all publications, getting publications you own, and fetching publications by their names.
|
|
||||||
|
|
||||||
#### Fetch All Publications
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const publications = await mediumAccount.getAllPublications();
|
|
||||||
publications.forEach(pub => console.log(pub.name, pub.id));
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Fetch Publications Owned By You
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const ownPublications = await mediumAccount.getOwnPublications();
|
|
||||||
ownPublications.forEach(pub => console.log(pub.name, pub.id));
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Fetch a Publication by Name
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const pubName = 'Your Publication Name';
|
|
||||||
const specificPublication = await mediumAccount.getPublicationByName(pubName);
|
|
||||||
if (specificPublication) {
|
|
||||||
console.log(specificPublication);
|
|
||||||
} else {
|
|
||||||
console.log(`Publication with name ${pubName} not found.`);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. Creating and Managing Posts
|
|
||||||
|
|
||||||
To create posts within a publication, you need to define the post data and use the publication object to create a post.
|
|
||||||
|
|
||||||
#### Define Post Data
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const newPostData: IPostData = {
|
|
||||||
title: 'My First Post',
|
|
||||||
contentFormat: 'markdown',
|
|
||||||
content: '# Hello World\nThis is my first post!',
|
|
||||||
canonicalUrl: 'https://yourcoolsite.com/first-post',
|
|
||||||
tags: ['example', 'first', 'post'],
|
|
||||||
publishStatus: 'draft'
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Create a New Post
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
if (specificPublication) {
|
|
||||||
const newPost = await specificPublication.createPost(newPostData);
|
|
||||||
console.log(newPost);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6. Error Handling
|
|
||||||
|
|
||||||
Effective error handling is essential when interacting with APIs. Make sure to wrap your asynchronous code in try/catch blocks to handle any rejected promises.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
try {
|
|
||||||
const result = await mediumAccount.getAccountInfo();
|
|
||||||
console.log(result);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to fetch account information:', error);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Complete Example
|
|
||||||
|
|
||||||
Here is a complete example script that demonstrates the major functionalities of the `@apiclient.xyz/medium` package.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { MediumAccount, IPostData } from '@apiclient.xyz/medium';
|
|
||||||
|
|
||||||
async function run() {
|
|
||||||
const mediumAccount = new MediumAccount('YOUR_ACCESS_TOKEN_HERE');
|
|
||||||
await mediumAccount.readyDeferred.promise;
|
|
||||||
|
|
||||||
// Fetch and display account information
|
|
||||||
const accountInfo = await mediumAccount.getAccountInfo();
|
|
||||||
console.log('Account Info:', accountInfo);
|
|
||||||
|
|
||||||
// Fetch and display all publications
|
|
||||||
const publications = await mediumAccount.getAllPublications();
|
|
||||||
publications.forEach(pub => console.log('Publication Name:', pub.name, 'ID:', pub.id));
|
|
||||||
|
|
||||||
// Fetch and display publications owned by the user
|
|
||||||
const ownPublications = await mediumAccount.getOwnPublications();
|
|
||||||
ownPublications.forEach(pub => console.log('Own Publication Name:', pub.name, 'ID:', pub.id));
|
|
||||||
|
|
||||||
// Fetch a specific publication by name
|
|
||||||
const pubName = 'Your Publication Name';
|
|
||||||
const specificPublication = await mediumAccount.getPublicationByName(pubName);
|
|
||||||
if (specificPublication) {
|
|
||||||
console.log('Specific Publication:', specificPublication);
|
|
||||||
|
|
||||||
// Define new post data
|
|
||||||
const newPostData: IPostData = {
|
|
||||||
title: 'My First Post',
|
|
||||||
contentFormat: 'markdown',
|
|
||||||
content: '# Hello World\nThis is my first post!',
|
|
||||||
canonicalUrl: 'https://yourcoolsite.com/first-post',
|
|
||||||
tags: ['example', 'first', 'post'],
|
|
||||||
publishStatus: 'draft'
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create a new post
|
|
||||||
const newPost = await specificPublication.createPost(newPostData);
|
|
||||||
console.log('New Post:', newPost);
|
|
||||||
} else {
|
|
||||||
console.log(`Publication with name ${pubName} not found.`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run().catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### Fetching Publication Contributors
|
|
||||||
|
|
||||||
If you want to see the contributors of a publication, you can fetch them and display the relevant details:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const fetchContributors = async (publicationId: string) => {
|
|
||||||
const response = await mediumAccount.request(`/publications/${publicationId}/contributors`, 'GET');
|
|
||||||
const contributors: { publicationId: string; userId: string; role: string; }[] = response.data;
|
|
||||||
contributors.forEach(contributor => {
|
|
||||||
console.log(`User ID: ${contributor.userId}, Role: ${contributor.role}`);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
await fetchContributors('SamplePublicationId');
|
|
||||||
```
|
|
||||||
|
|
||||||
### Advanced Post Management
|
|
||||||
|
|
||||||
Depending on the use case, you might need to fetch posts by specific criteria, update posts, or delete them. For this example, let's assume updating and deleting posts functions are supported by the Medium API, even though those capabilities aren't documented here.
|
|
||||||
|
|
||||||
#### Fetch a Post by ID
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const fetchPostById = async (publication: MediumPublication, postId: string) => {
|
|
||||||
const response = await mediumAccount.request(`/publications/${publication.id}/posts/${postId}`, 'GET');
|
|
||||||
const post = response.data;
|
|
||||||
console.log(post);
|
|
||||||
};
|
|
||||||
|
|
||||||
await fetchPostById(specificPublication, 'SamplePostId');
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Update a Post
|
|
||||||
|
|
||||||
Let's assume we have an endpoint for updating posts. The method might look like this:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const updatePost = async (publication: MediumPublication, postId: string, newData: Partial<IPostData>) => {
|
|
||||||
const response = await mediumAccount.request(`/publications/${publication.id}/posts/${postId}`, 'PUT', newData);
|
|
||||||
console.log('Updated Post:', response.data);
|
|
||||||
};
|
|
||||||
|
|
||||||
const updatedData: Partial<IPostData> = {
|
|
||||||
title: 'Updated Title',
|
|
||||||
content: '# Updated Content'
|
|
||||||
};
|
|
||||||
|
|
||||||
await updatePost(specificPublication, 'SamplePostId', updatedData);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Delete a Post
|
|
||||||
|
|
||||||
Similarly, assuming an endpoint exists for deleting posts:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const deletePost = async (publication: MediumPublication, postId: string) => {
|
|
||||||
const response = await mediumAccount.request(`/publications/${publication.id}/posts/${postId}`, 'DELETE');
|
|
||||||
console.log('Deleted Post', response.statusCode);
|
|
||||||
};
|
|
||||||
|
|
||||||
await deletePost(specificPublication, 'SamplePostId');
|
|
||||||
```
|
|
||||||
|
|
||||||
By following this guide, you should be able to leverage the extensive features provided by the `@apiclient.xyz/medium` package. From account management to creating and managing posts within publications, this guide offers the complete scenarios you need in order to interact effectively with the Medium API using Node.js and TypeScript.
|
|
||||||
|
|
||||||
### Extensions
|
|
||||||
|
|
||||||
Consider creating more complex interactions by combining different endpoint requests. For example:
|
|
||||||
|
|
||||||
- Creating a scheduled post by integrating with a scheduling library like node-schedule.
|
|
||||||
- Fetching and analyzing post stats if such endpoints are provided by Medium.
|
|
||||||
- Automating cross-platform publication by combining Medium's API with other platforms' APIs.
|
|
||||||
|
|
||||||
The flexibility and power of Node.js along with the typed safety of TypeScript provide a robust environment for developing applications that interact with web APIs efficiently and effectively.
|
|
||||||
|
|
||||||
Start by running the complete example script to get familiar with the basic functionalities. Build upon these examples to create feature-rich applications that make extensive use of Medium's capabilities.
|
|
||||||
|
|
||||||
Always ensure to consult Medium's API documentation for any updates or additional features that may be available for further enhancement and optimization of your integrations.
|
|
||||||
undefined
|
|
||||||
|
@ -7,7 +7,7 @@ const testQenv = new Qenv('./', './.nogit/');
|
|||||||
let testMediumAccount: medium.MediumAccount;
|
let testMediumAccount: medium.MediumAccount;
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
testMediumAccount = new medium.MediumAccount(await testQenv.getEnvVarOnDemand('MEDIUM_API_TOKEN'));
|
testMediumAccount = new medium.MediumAccount(testQenv.getEnvVarOnDemand('MEDIUM_API_TOKEN'));
|
||||||
expect(testMediumAccount).toBeInstanceOf(medium.MediumAccount);
|
expect(testMediumAccount).toBeInstanceOf(medium.MediumAccount);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* autocreated commitinfo by @push.rocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/medium',
|
name: '@mojoio/medium',
|
||||||
version: '1.0.7',
|
version: '1.0.5',
|
||||||
description: 'An unofficial Medium.com API package that enables interaction with Medium's features using Node.js.'
|
description: 'an unofficial medium.com API package'
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,11 @@ export interface IMediumAccountData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Medium account with various functionalities to interact with Medium's API.
|
*
|
||||||
*/
|
*/
|
||||||
export class MediumAccount implements IMediumAccountData {
|
export class MediumAccount implements IMediumAccountData {
|
||||||
|
// STATIC
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
private accessToken: string;
|
private accessToken: string;
|
||||||
public readyDeferred = plugins.smartpromise.defer();
|
public readyDeferred = plugins.smartpromise.defer();
|
||||||
@ -22,104 +24,43 @@ export class MediumAccount implements IMediumAccountData {
|
|||||||
url: string;
|
url: string;
|
||||||
imageUrl: string;
|
imageUrl: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a new instance of the MediumAccount class.
|
|
||||||
* @param accessTokenArg - The access token for the Medium API.
|
|
||||||
*/
|
|
||||||
constructor(accessTokenArg: string) {
|
constructor(accessTokenArg: string) {
|
||||||
this.accessToken = accessTokenArg;
|
this.accessToken = accessTokenArg;
|
||||||
this.getAccountInfo().then((dataArg) => {
|
this.getAccountInfo().then((dataArg) => {
|
||||||
if (dataArg) {
|
Object.assign(this, dataArg);
|
||||||
Object.assign(this, dataArg);
|
this.readyDeferred.resolve();
|
||||||
this.readyDeferred.resolve();
|
|
||||||
} else {
|
|
||||||
this.readyDeferred.reject('Failed to fetch account info.');
|
|
||||||
}
|
|
||||||
}).catch(error => {
|
|
||||||
console.error('Error fetching account info:', error);
|
|
||||||
this.readyDeferred.reject(error);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public async getAccountInfo(): Promise<IMediumAccountData> {
|
||||||
* Fetches the account information from Medium.
|
const result = await this.request('/me', 'GET');
|
||||||
* @returns A promise that resolves to the account data.
|
const accountData = result.body.data;
|
||||||
*/
|
return accountData;
|
||||||
public async getAccountInfo(): Promise<IMediumAccountData | undefined> {
|
|
||||||
try {
|
|
||||||
const result = await this.request('/me', 'GET');
|
|
||||||
console.log(result.statusCode);
|
|
||||||
const accountData: IMediumAccountData = result.body.data;
|
|
||||||
return accountData;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error in getAccountInfo:', error);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches all publications associated with this account.
|
|
||||||
* @returns A promise that resolves to an array of MediumPublication objects.
|
|
||||||
*/
|
|
||||||
public async getAllPublications(): Promise<MediumPublication[]> {
|
public async getAllPublications(): Promise<MediumPublication[]> {
|
||||||
const result = await this.request(`/users/${this.id}/publications`, 'GET');
|
return MediumPublication.getAllPublications(this);
|
||||||
return result.data.map((pub: any) => new MediumPublication(this, pub));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches all publications authored by this account.
|
|
||||||
* @returns A promise that resolves to an array of MediumPublication objects.
|
|
||||||
*/
|
|
||||||
public async getOwnPublications(): Promise<MediumPublication[]> {
|
public async getOwnPublications(): Promise<MediumPublication[]> {
|
||||||
const allPublications = await this.getAllPublications();
|
return MediumPublication.getOwnPublications(this);
|
||||||
const ownPublications: MediumPublication[] = [];
|
|
||||||
|
|
||||||
for (const publication of allPublications) {
|
|
||||||
const response = await this.request(`/publications/${publication.id}/contributors`, 'GET');
|
|
||||||
const contributors: { publicationId: string; userId: string; role: string; }[] = response.data;
|
|
||||||
|
|
||||||
if (contributors.some(contributor => contributor.userId === this.id)) {
|
|
||||||
ownPublications.push(publication);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ownPublications;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public async getPublicationByName(nameArg: string): Promise<MediumPublication> {
|
||||||
* Fetches a publication by its name.
|
return MediumPublication.getPublicationByName(this, nameArg);
|
||||||
* @param nameArg - The name of the publication.
|
|
||||||
* @returns A promise that resolves to the MediumPublication object.
|
|
||||||
*/
|
|
||||||
public async getPublicationByName(nameArg: string): Promise<MediumPublication | undefined> {
|
|
||||||
const publications = await this.getAllPublications();
|
|
||||||
return publications.find(publication => publication.name === nameArg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public async request(routeArg: string, methodArg: 'POST' | 'GET', payloadArg?: any) {
|
||||||
* Makes an authenticated request to the Medium API.
|
const response = await plugins.smartrequest.request(`${this.baseApiDomain}${routeArg}`, {
|
||||||
* @param routeArg - The API route to request.
|
headers: {
|
||||||
* @param methodArg - The HTTP method to use for the request.
|
Authorization: `Bearer ${this.accessToken}`,
|
||||||
* @param payloadArg - Optional payload for POST requests.
|
'Content-Type': 'application/json',
|
||||||
* @returns A promise that resolves to the API response.
|
Accept: 'application/json',
|
||||||
*/
|
'Accept-Charset': 'utf-8',
|
||||||
public async request(routeArg: string, methodArg: 'POST' | 'GET', payloadArg?: any): Promise<any> {
|
},
|
||||||
try {
|
method: methodArg,
|
||||||
const response = await plugins.smartrequest.request(`${this.baseApiDomain}${routeArg}`, {
|
requestBody: payloadArg ? JSON.stringify(payloadArg) : null
|
||||||
headers: {
|
});
|
||||||
Authorization: `Bearer ${this.accessToken}`,
|
return response;
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Accept: 'application/json',
|
|
||||||
'Accept-Charset': 'utf-8',
|
|
||||||
},
|
|
||||||
method: methodArg,
|
|
||||||
keepAlive: false,
|
|
||||||
requestBody: payloadArg ? JSON.stringify(payloadArg) : null
|
|
||||||
});
|
|
||||||
return response;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error in request:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,9 @@ export interface IPostData {
|
|||||||
|
|
||||||
export class MediumPost implements IPostData {
|
export class MediumPost implements IPostData {
|
||||||
// STATIC
|
// STATIC
|
||||||
public static async createPost(mediumPublication: MediumPublication, data: IPostData): Promise<MediumPost> {
|
public static async createPost(mediumPublicationArg: MediumPublication, dataArg: IPostData) {
|
||||||
const response = await mediumPublication.mediumAccountRef.request(`/publications/${mediumPublication.id}/posts`, 'POST', data);
|
const response = await mediumPublicationArg.mediumAccountRef.request(`/publications/${mediumPublicationArg.id}/posts`, 'POST', dataArg);
|
||||||
const post = new MediumPost(mediumPublication, response.data);
|
const post = new MediumPost(mediumPublicationArg, response.body.data);
|
||||||
return post;
|
return post;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,8 +28,7 @@ export class MediumPost implements IPostData {
|
|||||||
tags: string[];
|
tags: string[];
|
||||||
publishStatus: 'public' | 'draft' | 'unlisted';
|
publishStatus: 'public' | 'draft' | 'unlisted';
|
||||||
|
|
||||||
constructor(mediumPublication: MediumPublication, data: IPostData) {
|
constructor(mediumPublication: MediumPublication, dataArg: IPostData) {
|
||||||
this.mediumPublicationRef = mediumPublication;
|
|
||||||
Object.assign(this, data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,33 +12,45 @@ export interface IMediumPublication {
|
|||||||
|
|
||||||
export class MediumPublication implements IMediumPublication {
|
export class MediumPublication implements IMediumPublication {
|
||||||
// STATIC
|
// STATIC
|
||||||
public static async getAllPublications(mediumAccount: MediumAccount): Promise<MediumPublication[]> {
|
public static async getAllPublications(mediumAccount: MediumAccount) {
|
||||||
await mediumAccount.readyDeferred.promise;
|
await mediumAccount.readyDeferred.promise;
|
||||||
|
const returnArray: MediumPublication[] = [];
|
||||||
const response = await mediumAccount.request(`/users/${mediumAccount.id}/publications`, 'GET');
|
const response = await mediumAccount.request(`/users/${mediumAccount.id}/publications`, 'GET');
|
||||||
const publicationsDataArray: IMediumPublication[] = response.data;
|
const publicationsDataArray: IMediumPublication[] = response.body.data;
|
||||||
return publicationsDataArray.map(publicationData => new MediumPublication(mediumAccount, publicationData));
|
for (const publicationData of publicationsDataArray) {
|
||||||
|
const publication = new MediumPublication(mediumAccount, publicationData);
|
||||||
|
returnArray.push(publication);
|
||||||
|
}
|
||||||
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getOwnPublications(mediumAccount: MediumAccount): Promise<MediumPublication[]> {
|
public static async getOwnPublications(mediumAccount: MediumAccount) {
|
||||||
await mediumAccount.readyDeferred.promise;
|
await mediumAccount.readyDeferred.promise;
|
||||||
const allPublications = await this.getAllPublications(mediumAccount);
|
const allPublications = await this.getAllPublications(mediumAccount);
|
||||||
const ownPublications: MediumPublication[] = [];
|
const ownPublications: MediumPublication[] = [];
|
||||||
|
for (const publicationArg of allPublications) {
|
||||||
for (const publication of allPublications) {
|
const response = await mediumAccount.request(
|
||||||
const response = await mediumAccount.request(`/publications/${publication.id}/contributors`, 'GET');
|
`/publications/${publicationArg.id}/contributors`,
|
||||||
const contributors: { publicationId: string; userId: string; role: string; }[] = response.data;
|
'GET'
|
||||||
|
);
|
||||||
if (contributors.some(contributor => contributor.userId === mediumAccount.id)) {
|
const contributors: {
|
||||||
ownPublications.push(publication);
|
publicationId: string;
|
||||||
|
userId: string;
|
||||||
|
role: string;
|
||||||
|
}[] = response.body.data;
|
||||||
|
for (const contributor of contributors) {
|
||||||
|
if (contributor.userId === mediumAccount.id) {
|
||||||
|
ownPublications.push(publicationArg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ownPublications;
|
return ownPublications;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getPublicationByName(mediumAccount: MediumAccount, publicationName: string): Promise<MediumPublication | undefined> {
|
public static async getPublicationByName(mediumAccountArg: MediumAccount, publicationNameArg: string) {
|
||||||
const publications = await this.getAllPublications(mediumAccount);
|
const publications = await this.getAllPublications(mediumAccountArg);
|
||||||
return publications.find(publication => publication.name === publicationName);
|
return publications.find(publicationArg => publicationArg.name === publicationNameArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
@ -50,13 +62,13 @@ export class MediumPublication implements IMediumPublication {
|
|||||||
url: string;
|
url: string;
|
||||||
imageUrl: string;
|
imageUrl: string;
|
||||||
|
|
||||||
constructor(mediumAccount: MediumAccount, data: IMediumPublication) {
|
constructor(mediumAccount: MediumAccount, dataArg: IMediumPublication) {
|
||||||
this.mediumAccountRef = mediumAccount;
|
this.mediumAccountRef = mediumAccount;
|
||||||
Object.assign(this, data);
|
Object.assign(this, dataArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createPost(data: IPostData): Promise<MediumPost> {
|
public async createPost(dataArg: IPostData): Promise<MediumPost> {
|
||||||
const result = await MediumPost.createPost(this, data);
|
const result = await MediumPost.createPost(this, dataArg);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user