@deskcrew/docusaurus-plugin 1.0.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 +65 -0
- package/build-tag.js +102 -0
- package/index.d.ts +23 -0
- package/index.js +27 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeskCrew
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @deskcrew/docusaurus-plugin
|
|
2
|
+
|
|
3
|
+
Add the [DeskCrew](https://deskcrew.io) support widget — live chat, instant
|
|
4
|
+
answers from your help articles and a help center — to every page of your
|
|
5
|
+
Docusaurus site.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @deskcrew/docusaurus-plugin
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Add the plugin to your `docusaurus.config.js` and pass your widget key:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// docusaurus.config.js
|
|
19
|
+
module.exports = {
|
|
20
|
+
// ...
|
|
21
|
+
plugins: [
|
|
22
|
+
[
|
|
23
|
+
'@deskcrew/docusaurus-plugin',
|
|
24
|
+
{
|
|
25
|
+
widgetKey: 'pub_xxxxxxxx', // required — from Dashboard → Install
|
|
26
|
+
// board: 'your-workspace', // optional
|
|
27
|
+
// color: '#4f46e5', // optional accent colour
|
|
28
|
+
// position: 'right', // optional: 'left' | 'right'
|
|
29
|
+
// greeting: 'Hi! How can we help?', // optional
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
],
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Start or build your site and the chat launcher appears on every page.
|
|
37
|
+
|
|
38
|
+
## Options
|
|
39
|
+
|
|
40
|
+
| Option | Type | Required | Description |
|
|
41
|
+
| ----------- | ------------------- | -------- | -------------------------------------------------- |
|
|
42
|
+
| `widgetKey` | `string` | yes | Your public key (`pub_…`). |
|
|
43
|
+
| `board` | `string` | no | Board slug (lowercase letters, numbers, dashes). |
|
|
44
|
+
| `color` | `string` | no | Accent colour as a 6-digit hex value, e.g. `#4f46e5`. |
|
|
45
|
+
| `position` | `'left' \| 'right'` | no | Which side the launcher sits on. |
|
|
46
|
+
| `greeting` | `string` | no | Greeting shown on the launcher. |
|
|
47
|
+
|
|
48
|
+
If `widgetKey` is missing or malformed the plugin prints a build-time warning
|
|
49
|
+
and adds nothing — your site still builds.
|
|
50
|
+
|
|
51
|
+
## How it works
|
|
52
|
+
|
|
53
|
+
The plugin appends a single `<script src="https://deskcrew.io/desk.js">` tag to
|
|
54
|
+
every page via the `injectHtmlTags` lifecycle (`postBodyTags`). `desk.js` reads
|
|
55
|
+
your settings from its `data-*` attributes and derives its API origin from its
|
|
56
|
+
own `src`, so there is nothing else to configure.
|
|
57
|
+
|
|
58
|
+
## No account yet?
|
|
59
|
+
|
|
60
|
+
[Create one free](https://deskcrew.io/signup) — no card needed — then copy your
|
|
61
|
+
key from [Dashboard → Install](https://deskcrew.io/dashboard/install).
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT © DeskCrew · [deskcrew.io](https://deskcrew.io) · hello@deskcrew.io
|
package/build-tag.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Framework-agnostic core for the DeskCrew Docusaurus plugin.
|
|
2
|
+
//
|
|
3
|
+
// Everything here is a pure function of its options — no Docusaurus imports, no
|
|
4
|
+
// I/O — so it can be unit-tested on its own (see test/build-tag.cjs).
|
|
5
|
+
|
|
6
|
+
'use strict'
|
|
7
|
+
|
|
8
|
+
/** The canonical DeskCrew widget bundle. desk.js derives its API origin from this src. */
|
|
9
|
+
const WIDGET_SRC = 'https://deskcrew.io/desk.js'
|
|
10
|
+
|
|
11
|
+
// Strict shapes: a value is only ever placed into markup after it matches one of
|
|
12
|
+
// these, so nothing arbitrary can reach the page.
|
|
13
|
+
const KEY_RE = /^pub_[A-Za-z0-9]{8,64}$/
|
|
14
|
+
const BOARD_RE = /^[a-z0-9-]+$/
|
|
15
|
+
const COLOR_RE = /^#[0-9a-fA-F]{6}$/
|
|
16
|
+
const POSITIONS = new Set(['left', 'right'])
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Validate options and produce the ordered [name, value] attribute list for the
|
|
20
|
+
* widget <script>. Returns `{ attrs: null }` (nothing should be injected) when
|
|
21
|
+
* the widget key is missing or malformed; invalid *optional* values are dropped
|
|
22
|
+
* with a warning but never block the widget.
|
|
23
|
+
*
|
|
24
|
+
* @param {Record<string, unknown> | undefined | null} options
|
|
25
|
+
* @returns {{ attrs: string[][] | null, warnings: string[] }}
|
|
26
|
+
*/
|
|
27
|
+
function buildAttrs(options) {
|
|
28
|
+
const warnings = []
|
|
29
|
+
const opts = options || {}
|
|
30
|
+
|
|
31
|
+
const key = typeof opts.widgetKey === 'string' ? opts.widgetKey.trim() : ''
|
|
32
|
+
if (!key) {
|
|
33
|
+
warnings.push(
|
|
34
|
+
'[deskcrew] No widgetKey was provided — the support widget was NOT added. ' +
|
|
35
|
+
'Copy your pub_ key from https://deskcrew.io/dashboard/install.',
|
|
36
|
+
)
|
|
37
|
+
return { attrs: null, warnings }
|
|
38
|
+
}
|
|
39
|
+
if (!KEY_RE.test(key)) {
|
|
40
|
+
warnings.push(
|
|
41
|
+
`[deskcrew] widgetKey "${key}" is not a valid public key (expected pub_...) — ` +
|
|
42
|
+
'the support widget was NOT added.',
|
|
43
|
+
)
|
|
44
|
+
return { attrs: null, warnings }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const attrs = [
|
|
48
|
+
['src', WIDGET_SRC],
|
|
49
|
+
['data-key', key],
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
const board = typeof opts.board === 'string' ? opts.board.trim() : ''
|
|
53
|
+
if (board) {
|
|
54
|
+
if (BOARD_RE.test(board)) attrs.push(['data-board', board])
|
|
55
|
+
else warnings.push(`[deskcrew] board "${board}" is not a valid slug (a-z, 0-9, dashes) — ignored.`)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const color = typeof opts.color === 'string' ? opts.color.trim() : ''
|
|
59
|
+
if (color) {
|
|
60
|
+
if (COLOR_RE.test(color)) attrs.push(['data-color', color])
|
|
61
|
+
else warnings.push(`[deskcrew] color "${color}" is not a 6-digit hex value like #4f46e5 — ignored.`)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const position = typeof opts.position === 'string' ? opts.position.trim() : ''
|
|
65
|
+
if (position) {
|
|
66
|
+
if (POSITIONS.has(position)) attrs.push(['data-position', position])
|
|
67
|
+
else warnings.push(`[deskcrew] position "${position}" must be "left" or "right" — ignored.`)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const greeting = typeof opts.greeting === 'string' ? opts.greeting.trim() : ''
|
|
71
|
+
if (greeting) attrs.push(['data-greeting', greeting])
|
|
72
|
+
|
|
73
|
+
return { attrs, warnings }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Escape a value for use inside a double-quoted HTML attribute.
|
|
78
|
+
* @param {unknown} value
|
|
79
|
+
*/
|
|
80
|
+
function escapeHtmlAttr(value) {
|
|
81
|
+
return String(value)
|
|
82
|
+
.replace(/&/g, '&')
|
|
83
|
+
.replace(/"/g, '"')
|
|
84
|
+
.replace(/</g, '<')
|
|
85
|
+
.replace(/>/g, '>')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Build the canonical `<script ...>` tag string injected on every page, or
|
|
90
|
+
* `null` when options are invalid.
|
|
91
|
+
*
|
|
92
|
+
* @param {Record<string, unknown> | undefined | null} options
|
|
93
|
+
* @returns {{ tag: string | null, warnings: string[] }}
|
|
94
|
+
*/
|
|
95
|
+
function buildTag(options) {
|
|
96
|
+
const { attrs, warnings } = buildAttrs(options)
|
|
97
|
+
if (!attrs) return { tag: null, warnings }
|
|
98
|
+
const rendered = attrs.map(([name, value]) => `${name}="${escapeHtmlAttr(value)}"`).join(' ')
|
|
99
|
+
return { tag: `<script ${rendered} defer></script>`, warnings }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = { WIDGET_SRC, buildAttrs, buildTag }
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LoadContext, Plugin } from '@docusaurus/types'
|
|
2
|
+
|
|
3
|
+
declare function deskcrewPlugin(
|
|
4
|
+
context: LoadContext,
|
|
5
|
+
options?: deskcrewPlugin.DeskcrewPluginOptions,
|
|
6
|
+
): Plugin<void>
|
|
7
|
+
|
|
8
|
+
declare namespace deskcrewPlugin {
|
|
9
|
+
interface DeskcrewPluginOptions {
|
|
10
|
+
/** Your DeskCrew public widget key, e.g. "pub_xxxxxxxx". Required. */
|
|
11
|
+
widgetKey: string
|
|
12
|
+
/** Board slug (lowercase letters, numbers and dashes). Optional. */
|
|
13
|
+
board?: string
|
|
14
|
+
/** Accent colour as a 6-digit hex value, e.g. "#4f46e5". Optional. */
|
|
15
|
+
color?: string
|
|
16
|
+
/** Which side the launcher sits on. Optional. */
|
|
17
|
+
position?: 'left' | 'right'
|
|
18
|
+
/** Greeting shown on the launcher. Optional. */
|
|
19
|
+
greeting?: string
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export = deskcrewPlugin
|
package/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { buildTag } = require('./build-tag.js')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* DeskCrew Docusaurus plugin.
|
|
7
|
+
*
|
|
8
|
+
* Adds the DeskCrew support widget (live chat, instant answers and a help
|
|
9
|
+
* centre) to every page. It appends a single `<script src="…/desk.js">` tag via
|
|
10
|
+
* the `injectHtmlTags` lifecycle (`postBodyTags`); desk.js reads its `data-*`
|
|
11
|
+
* attributes and derives its API origin from its own src.
|
|
12
|
+
*
|
|
13
|
+
* @param {unknown} _context Docusaurus LoadContext (unused).
|
|
14
|
+
* @param {Record<string, unknown>} [options]
|
|
15
|
+
* @returns {{ name: string, injectHtmlTags: () => { postBodyTags?: string[] } }}
|
|
16
|
+
*/
|
|
17
|
+
module.exports = function deskcrewPlugin(_context, options) {
|
|
18
|
+
const { tag, warnings } = buildTag(options || {})
|
|
19
|
+
for (const message of warnings) console.warn(message)
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
name: 'docusaurus-plugin-deskcrew',
|
|
23
|
+
injectHtmlTags() {
|
|
24
|
+
return tag ? { postBodyTags: [tag] } : {}
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deskcrew/docusaurus-plugin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Docusaurus plugin that adds the DeskCrew support widget (live chat, instant answers and a help center) to every page.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"docusaurus",
|
|
7
|
+
"docusaurus-plugin",
|
|
8
|
+
"deskcrew",
|
|
9
|
+
"support",
|
|
10
|
+
"chat",
|
|
11
|
+
"widget",
|
|
12
|
+
"helpdesk",
|
|
13
|
+
"live-chat"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://deskcrew.io",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"email": "hello@deskcrew.io"
|
|
18
|
+
},
|
|
19
|
+
"author": "DeskCrew <hello@deskcrew.io> (https://deskcrew.io)",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"type": "commonjs",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./index.d.ts",
|
|
25
|
+
"require": "./index.js",
|
|
26
|
+
"default": "./index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"main": "index.js",
|
|
30
|
+
"types": "index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"index.js",
|
|
33
|
+
"build-tag.js",
|
|
34
|
+
"index.d.ts",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"test": "node --test",
|
|
43
|
+
"typecheck": "tsc --noEmit"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@docusaurus/core": ">=2"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@docusaurus/types": ">=2",
|
|
50
|
+
"typescript": "^5"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
}
|
|
55
|
+
}
|