{"_id":"@addoinc/strapi-plugin-io","name":"@addoinc/strapi-plugin-io","dist-tags":{"latest":"1.1.2"},"versions":{"1.1.2":{"$schema":"https://json.schemastore.org/package","name":"@addoinc/strapi-plugin-io","version":"1.1.2","description":"A plugin for Strapi CMS that provides the ability for Socket IO integration","scripts":{"lint":"eslint . --fix","format":"prettier --write **/*.{ts,js,json,yml}"},"author":{"name":"@ComfortablyCoding","url":"https://github.com/ComfortablyCoding"},"maintainers":[{"name":"nkaddoinc","email":"nimish@addoinc.com"}],"homepage":"https://github.com/ComfortablyCoding/strapi-plugin-io#readme","repository":{"type":"git","url":"git+https://github.com/ComfortablyCoding/strapi-plugin-io.git"},"bugs":{"url":"https://github.com/ComfortablyCoding/strapi-plugin-io/issues"},"dependencies":{"socket.io":"^4.4.1"},"devDependencies":{"@strapi-community/eslint-config":"^0.2.0","eslint":"^8.11.0","eslint-config-prettier":"^8.5.0","prettier":"^2.6.0"},"peerDependencies":{"@strapi/strapi":"^4.1.5","lodash":"^4.17.21","yup":"^0.32.11"},"strapi":{"name":"io","displayName":"IO","description":"A plugin for Strapi CMS that provides the ability for Socket IO integration","kind":"plugin"},"engines":{"node":">=12.x.x <=16.x.x","npm":">=6.0.0"},"keywords":["strapi","strapi-plugin","plugin","strapi plugin","socket io","io"],"license":"MIT","gitHead":"bba7e76cab82717a8da23fe3b5235fe0787e8cf1","_id":"@addoinc/strapi-plugin-io@1.1.2","_nodeVersion":"14.19.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-Sd7CKqi9SYZGzGT2o9DbaUElJTsLLyTQpzHl4d84v4NwM3RbCic+awH3zToB7vQ/ac5wp0RHglJpfXsNsiV9dQ==","shasum":"a04fa7d2f5325b9fdb011daa5a40b26023abcde8","tarball":"https://registry.npmjs.org/@addoinc/strapi-plugin-io/-/strapi-plugin-io-1.1.2.tgz","fileCount":24,"unpackedSize":19148,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCvNjDfGtSyblYPR9ovW8ZL2sj2k0kZIDjmvZ6d7/4JNQIhAKZ5FQvnWIpwkd6L1PryE0iJ7pWe34BhEojMm7j0uVFC"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjoGRzACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpzLhAAiw/8KaesF2GQNmHcr1qkjfvspItobkGJ+MQ/Ic3XVtPVUyvk\r\nSA9nYC3PoJdrkCnBk3A9UHcqMpuxONQ+GUANJONcCqHSTEsr2s3NbI6iGOH/\r\nuHMVyRzODCR16WudHy8QbyY5h2jzrqiJPVRnIQf6jmJkNZoDfDa182F5UL6W\r\nGOki+spjXiLT7J7ng7Z5PYj7Mn9cQqi4a/nt1Emu8G4zRdD+ZU9HBAMot+Yt\r\n5KnlbzVooBLyH92L+RU+/ZmsvKfC2H47YIjoBtzzb+w9r6c26Sur+dl6bvTM\r\nqScqk1iIVCnij6RXa/gl/3CleQI/oUn2XheLw1RrkFb8g8gv40cG0m39mp7/\r\ns+FeyDMg6PMsXuINPB61G60eYGks/RbA4M2Ami5DzKJ30AiCcjVULnEN8XiT\r\n6WYBtjeMvzLUPqtaDm2N+s8/e5GGV5QrIJrdAHCCgocrPjKZ33jly1x0MoUu\r\nArNFQhjqAJWdIwYCX+Vl/AAIQ4Wb8TzN9e9DUU8xb5OhgTkQLx+t4JQxi6MF\r\nKtPc8VpSsRYk0tA+qGHfkIXYKNG3W3kufzE/ZXV8DIPyI8PNil9Qp5+8Eg+B\r\nmp9B+sixESTzDJvsTd4Tw3i5/iPsib1uNtQBIOLMqIBtYuI86luvo/eCSnUZ\r\nfm/OypZKme5U5b4AHtKYX7G/WECL6u1Mjwc=\r\n=J5eQ\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nkaddoinc","email":"nimish@addoinc.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/strapi-plugin-io_1.1.2_1671455859288_0.5323803465829913"},"_hasShrinkwrap":false}},"time":{"created":"2022-12-19T13:17:39.240Z","1.1.2":"2022-12-19T13:17:39.444Z","modified":"2022-12-19T13:17:39.627Z"},"maintainers":[{"name":"nkaddoinc","email":"nimish@addoinc.com"}],"description":"A plugin for Strapi CMS that provides the ability for Socket IO integration","homepage":"https://github.com/ComfortablyCoding/strapi-plugin-io#readme","keywords":["strapi","strapi-plugin","plugin","strapi plugin","socket io","io"],"repository":{"type":"git","url":"git+https://github.com/ComfortablyCoding/strapi-plugin-io.git"},"author":{"name":"@ComfortablyCoding","url":"https://github.com/ComfortablyCoding"},"bugs":{"url":"https://github.com/ComfortablyCoding/strapi-plugin-io/issues"},"license":"MIT","readme":"# strapi-plugin-io\n\nA plugin for [Strapi CMS](https://github.com/strapi/strapi) that provides the ability for [Socket IO](https://socket.io) integration\n\n[![Downloads](https://img.shields.io/npm/dm/strapi-plugin-io?style=for-the-badge)](https://img.shields.io/npm/dm/strapi-plugin-io?style=for-the-badge)\n[![Install size](https://img.shields.io/npm/l/strapi-plugin-io?style=for-the-badge)](https://img.shields.io/npm/l/strapi-plugin-io?style=for-the-badge)\n[![Package version](https://img.shields.io/github/v/release/ComfortablyCoding/strapi-plugin-io?style=for-the-badge)](https://img.shields.io/github/v/release/ComfortablyCoding/strapi-plugin-io?style=for-the-badge)\n\n## Requirements\n\nThe installation requirements are the same as Strapi itself and can be found in the documentation on the [Quick Start](https://strapi.io/documentation/developer-docs/latest/getting-started/quick-start.html) page in the Prerequisites info card.\n\n### Supported Strapi versions\n\n- v4.x.x\n\n**NOTE**: While this plugin may work with the older Strapi versions, they are not supported, it is always recommended to use the latest version of Strapi.\n\n## Installation\n\n```sh\nnpm install strapi-plugin-io\n\n# or\n\nyarn add strapi-plugin-io\n```\n\n## Configuration\n\nThe plugin configuration is stored in a config file located at `./config/plugins.js`.\n\n### Sample configuration\n\n```javascript\nmodule.exports = ({ env }) => ({\n  // ...\n  \"io\": {\n    \"enabled\": true,\n    \"config\": {\n      \"IOServerOptions\" :{\n        \"cors\": { \"origin\": \"http://localhost:5000\", \"methods\": [\"GET\"] },\n      },\n      \"contentTypes\": {\n        \"message\": \"*\",\n        \"chat\":[\"create\"]\n      },\n      \"events\":[\n        {\n          \"name\": \"connection\",\n          \"handler\": ({ strapi }, socket) => {\n            strapi.log.info(`[io] new connection with id ${socket.id}`);\n          },\n        },\n      ]\n    },\n  },\n  // ...\n});\n```\n\nThe above configuration will do the following:\n\n  1. Set the IO server options.\n  2. Emit all events for the messages content type and only the create event for the chats content type.\n  3. Log the socket id of any newly connected sockets.\n\n**IMPORTANT NOTE**: Make sure any sensitive data is stored in env files.\n\n## The Complete Plugin Configuration Object\n\n| Property | Description | Type | Default | Required |\n| -------- | ----------- | ---- | ------- | -------- |\n| IOServerOptions | The [Socket IO Server Options](https://socket.io/docs/v4/server-options). | Object | {} | No\n| contentTypes | The Content Types to emit events for. A \"*\" can be used to listen for all content types and events. | Object `or` String | {} | No |\n| contentTypes[apiName] | The events to listen for on the given content type. The apiName is the `singularName` in the [model schema](https://docs.strapi.io/developer-docs/latest/development/backend-customization/models.html#model-schema). The value can be an array of events or a \"*\" to listen for all. | Array `or` String | N/A | Yes |\n| events | Any server server side events to listen for | Array | [] | No |\n| events[x].name | The event name (case sensitive) | String | N/A | Yes |\n| events[x].handler | The function to execute when the event is triggered. The handlers first argument is the ctx containing the strapi instance, the subsequent parameters are in the same order as in the client emit event. For the built in \"connection\" event the subsequent parameter is the socket. | Function | N/A | Yes\n| publicRoleName | The name of the default role to be assigned to unauthenticated connections | String | \"Public\" | No\n\n## Currently Supported Emit events\n\n- `find`\n- `findOne`\n- `delete`\n- `create`\n- `update`\n- `publish`\n- `unpublish`\n- `createOrUpdate` (single content type only)\n\n## Emit Syntax\n\nAll events emitted have the following syntax `singularName:action`.\n\n## Emitting Custom Events\n\nThe server socket instance is attached to the strapi object. Custom event can be emitted via the emit or raw method.\n\n### Emit\n\nThe emit function accepts a specific event format (api::singularName.singularName.actionName) and will automatically verify permissions for all strapi roles (rooms).\n\n```javascript\nstrapi.$io.emit(\"api::message.message.someCustomAction\", data);\n```\n\n### Raw\n\nA raw emit **will not** verify any permissions before emitting.\n\n#### Raw emit to all rooms\n\n```javascript\nstrapi.$io.raw(\"customEvent\", data);\n```\n\n#### Raw emit to a specific room\n\n```javascript\nstrapi.$io.raw(\"customEvent\", data, {room: \"SOCKET_ID\"});\n```\n\n## Example Client Connections\n\nBelow are example client socket configurations.\n\n### Unauthenticated User connection\n\n```javascript\nconst { io } = require(\"socket.io-client\");\nconst SERVER_URL = \"http://localhost:1337\";\nconst socket = io(SERVER_URL);\n\n//  wait until socket connects before adding event listeners\nsocket.on(\"connect\", () => {\n  socket.on(\"message:update\", (data) => {\n    console.log(data)\n  });\n});\n```\n\n### Authenticated User connection\n\n```javascript\nconst { io } = require(\"socket.io-client\");\nconst SERVER_URL = \"http://localhost:1337\";\nconst JWT_TOKEN = \"your users JWT token\";\n\n// token will be verified, connection will be rejected if not a valid JWT\nconst socket = io(SERVER_URL, {\n  auth: { \n    token: JWT_TOKEN\n  },\n});\n\n//  wait until socket connects before adding event listeners\nsocket.on(\"connect\", () => {\n  socket.on(\"message:update\", (data) => {\n    console.log(data)\n  });\n});\n```\n\n## Bugs\n\nIf any bugs are found please report them as a [Github Issue](https://github.com/ComfortablyCoding/strapi-plugin-io/issues)\n","readmeFilename":"README.md"}