UNPKG

@wikoci/payloadjs

Version:

Payload CMS SDK for use in javascript

145 lines (108 loc) 2.59 kB
![](https://payloadcms.com/_next/image?url=https%3A%2F%2Fpayloadcms.com%2Fimages%2Fblog%2Fv1%2Fv1-announced.jpg&w=1920&q=75) # Payload CMS SDK + Plugin ## ✨ Features - Restful Method - Plugin Permission - Plugin to Upload multiples files once. - Plugin aggregate endpoints part of [Mongodb aggregate](https://www.mongodb.com/docs/manual/aggregation/) ### Installation ```js npm i @wikoci/payloadjs yarn @wikoci/payloadjs ``` ## SDK JS - Restfull ```js import {Payload} from "@wikoci/payloadjs" var payload =new Payload({ key:'', apiURL:'', mediaURL:'', debug:true }) ``` ### login() ```js payload.login("slug",data,options); ``` ### me() ```js payload.me("slug"); ``` ### logout() ```js payload.logout("slug"); ``` ### find() ```js payload.find("slug",params,options); ``` ### global() Find single collection type. ```js payload.global("slug"); ``` ### findOne() ```js payload.findOne("slug",ID); ``` ### create() ```js payload.find("slug",data,options); ``` ### update() ```js payload.find("slug",ID,data,options); ``` ### deleteOne() ```js payload.find("slug",ID); ``` ### setToken() ```js payload.setToken(token); ``` ### clearToken() ```js payload.clearToken(); ``` ### aggregate() ** require Plugin aggregate ** ```js //In server.js const {aggregateEndpoints} =require("@wikoci/payloadjs/plugins/mongodb") payload.init({ secret: process.env.PAYLOAD_SECRET, mongoURL: process.env.MONGODB_URI, express: app, onInit: () => { aggregateEndpoints(payload) //++ Add this line payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`); }, }); ``` ```js payload.aggregate("slug",pipeline); ``` ## Plugin ### Permission plugin > This plugin active all feature : createdBy , updatedBy , and Permission utility. ** Notice: ** 1- All slug contains `users` are allowed to use permission plugins and authentication execpt default payload users. Ex: customer-users , public-users , doa-users ```js //payload.config.js import {permission } from "@wikoci/payloadjs/plugin" const config ={ // Optional defaultPermission:{ slug: { auth: ["create", "readAny"], // default permissions for Auth User : create | readAny | readOwn | deleteAny | deleteOwn | updateOwn | updateAny | aggregate | readGlobal | createGlobal public: ["readAny"], // No auth user readAny | createAny | deleteAny | updateAny | readGlobal | createGlobal, readOnlyCreatedBy: true, // Admin UI readOnlyUpdatedBy: true, // Admin UI }, } } plugins:[ permission(config) ] ```