@deskcrew/angular 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 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,53 @@
1
+ # @deskcrew/angular
2
+
3
+ Add the [DeskCrew](https://deskcrew.io) support widget to an Angular app: live chat, AI answers grounded in your knowledge base, and a help center. One provider at bootstrap, one script tag, isolated in a Shadow DOM.
4
+
5
+ ## Install
6
+
7
+ ```
8
+ npm install @deskcrew/angular
9
+ ```
10
+
11
+ Standalone apps, in `src/app/app.config.ts`:
12
+
13
+ ```ts
14
+ import { ApplicationConfig } from '@angular/core'
15
+ import { provideDeskcrew } from '@deskcrew/angular'
16
+
17
+ export const appConfig: ApplicationConfig = {
18
+ providers: [provideDeskcrew({ widgetKey: 'pub_your_widget_key', board: 'your-board' })],
19
+ }
20
+ ```
21
+
22
+ NgModule apps: add the same `provideDeskcrew(...)` to the `providers` array of `AppModule`.
23
+
24
+ Prefer no code at all? Paste the tag from `buildTag(options).tag` into `src/index.html` before `</body>`; the provider does the same thing when the app boots.
25
+
26
+ Get the key from the Install page of your DeskCrew dashboard. With Angular SSR the server render does nothing and the browser bootstrap injects the widget.
27
+
28
+ ## What you get
29
+
30
+ - **AI answers grounded in your own help articles.** The assistant only answers from the knowledge base you publish, so it cannot invent product facts.
31
+ - **A human approves before anything sends.** Every AI draft waits in an approval queue. Nothing reaches a customer unreviewed.
32
+ - **Every conversation becomes a ticket.** Widget chats, emails and board posts land in one dashboard with full history.
33
+ - **Visitors who leave still get answered.** Leave an email address and the reply arrives by email.
34
+
35
+ ## Options
36
+
37
+ | Option | Required | Notes |
38
+ | ----------- | -------- | ------------------------------------------------------------------------------------ |
39
+ | `widgetKey` | yes | Your public widget key, `pub_...`, from the Install page of your DeskCrew dashboard. |
40
+ | `board` | no | Your board slug (lowercase letters, numbers, dashes). Enables the feedback link. |
41
+ | `color` | no | Accent colour as a 6-digit hex value, e.g. `#4f46e5`. |
42
+ | `position` | no | `right` (default) or `left`. |
43
+ | `greeting` | no | First line the launcher shows. |
44
+
45
+ Invalid optional values are dropped with a console warning; a missing or malformed key means the widget is not added at all, so a bad config can never put arbitrary markup on your page.
46
+
47
+ ## Privacy
48
+
49
+ The only thing this package adds to your site is one `<script>` tag that loads `https://deskcrew.io/desk.js` with your public key. The widget runs inside a Shadow DOM and does not touch your styles. Terms: https://deskcrew.io/terms. Privacy: https://deskcrew.io/privacy.
50
+
51
+ ## License
52
+
53
+ MIT
package/build-tag.js ADDED
@@ -0,0 +1,143 @@
1
+ // Framework-agnostic core for the DeskCrew widget packages.
2
+ //
3
+ // Everything here is a pure function of its options: no Astro imports, no I/O,
4
+ // so it can be unit-tested on its own (see test/build-tag.mjs).
5
+
6
+ /** The canonical DeskCrew widget bundle. desk.js derives its API origin from this src. */
7
+ export const WIDGET_SRC = 'https://deskcrew.io/desk.js'
8
+
9
+ // Strict shapes: a value is only ever placed into markup after it matches one of
10
+ // these, so nothing arbitrary can reach the page.
11
+ const KEY_RE = /^pub_[A-Za-z0-9]{8,64}$/
12
+ const BOARD_RE = /^[a-z0-9-]+$/
13
+ const COLOR_RE = /^#[0-9a-fA-F]{6}$/
14
+ const POSITIONS = new Set(['left', 'right'])
15
+
16
+ /**
17
+ * Validate options and produce the ordered [name, value] attribute list for the
18
+ * widget <script>. Returns `{ attrs: null }` (nothing should be injected) when
19
+ * the widget key is missing or malformed; invalid *optional* values are dropped
20
+ * with a warning but never block the widget.
21
+ *
22
+ * @param {Record<string, unknown> | undefined | null} options
23
+ * @returns {{ attrs: string[][] | null, warnings: string[] }}
24
+ */
25
+ export function buildAttrs(options) {
26
+ const warnings = []
27
+ const opts = options || {}
28
+
29
+ const key = typeof opts.widgetKey === 'string' ? opts.widgetKey.trim() : ''
30
+ if (!key) {
31
+ warnings.push(
32
+ '[deskcrew] No widgetKey was provided. The support widget was NOT added. ' +
33
+ 'Copy your pub_ key from https://deskcrew.io/dashboard/install.',
34
+ )
35
+ return { attrs: null, warnings }
36
+ }
37
+ if (!KEY_RE.test(key)) {
38
+ warnings.push(
39
+ `[deskcrew] widgetKey "${key}" is not a valid public key (expected pub_...). ` +
40
+ 'the support widget was NOT added.',
41
+ )
42
+ return { attrs: null, warnings }
43
+ }
44
+
45
+ const attrs = [
46
+ ['src', WIDGET_SRC],
47
+ ['data-key', key],
48
+ ]
49
+
50
+ const board = typeof opts.board === 'string' ? opts.board.trim() : ''
51
+ if (board) {
52
+ if (BOARD_RE.test(board)) attrs.push(['data-board', board])
53
+ else
54
+ warnings.push(`[deskcrew] board "${board}" is not a valid slug (a-z, 0-9, dashes). Ignored.`)
55
+ }
56
+
57
+ const color = typeof opts.color === 'string' ? opts.color.trim() : ''
58
+ if (color) {
59
+ if (COLOR_RE.test(color)) attrs.push(['data-color', color])
60
+ else
61
+ 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, '&amp;')
83
+ .replace(/"/g, '&quot;')
84
+ .replace(/</g, '&lt;')
85
+ .replace(/>/g, '&gt;')
86
+ }
87
+
88
+ /**
89
+ * Build the canonical `<script ...>` tag string for the widget (handy for
90
+ * debugging or manual placement), or `null` when options are invalid.
91
+ *
92
+ * @param {Record<string, unknown> | undefined | null} options
93
+ * @returns {{ tag: string | null, warnings: string[] }}
94
+ */
95
+ export 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
+ /**
103
+ * Escape a string for safe embedding as a JS literal inside an inline <script>.
104
+ * `<`, `>` and `&` are escaped so a value can never close the inline script tag.
105
+ * @param {unknown} value
106
+ */
107
+ function jsLiteral(value) {
108
+ return JSON.stringify(String(value))
109
+ .replace(/</g, '\\u003c')
110
+ .replace(/>/g, '\\u003e')
111
+ .replace(/&/g, '\\u0026')
112
+ }
113
+
114
+ /**
115
+ * Astro's `injectScript('head-inline', ...)` takes JS, not a raw external tag,
116
+ * so we emit a tiny bootstrap that creates the widget <script> element and
117
+ * appends it. Returns `{ code: null }` when options are invalid.
118
+ *
119
+ * @param {Record<string, unknown> | undefined | null} options
120
+ * @returns {{ code: string | null, warnings: string[] }}
121
+ */
122
+ export function buildBootstrap(options) {
123
+ const { attrs, warnings } = buildAttrs(options)
124
+ if (!attrs) return { code: null, warnings }
125
+
126
+ const dataLines = attrs
127
+ .filter(([name]) => name !== 'src')
128
+ .map(([name, value]) => ` s.setAttribute(${jsLiteral(name)}, ${jsLiteral(value)});`)
129
+ .join('\n')
130
+
131
+ const guard = `script[src=${JSON.stringify(WIDGET_SRC)}]`
132
+ const code =
133
+ '(function () {\n' +
134
+ ` if (document.querySelector(${jsLiteral(guard)})) return;\n` +
135
+ ' var s = document.createElement("script");\n' +
136
+ ` s.src = ${jsLiteral(WIDGET_SRC)};\n` +
137
+ ' s.defer = true;\n' +
138
+ (dataLines ? dataLines + '\n' : '') +
139
+ ' document.head.appendChild(s);\n' +
140
+ '})();'
141
+
142
+ return { code, warnings }
143
+ }
package/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ export interface DeskcrewOptions {
2
+ /** Your DeskCrew public widget key, e.g. "pub_xxxxxxxx". Required. */
3
+ widgetKey: string
4
+ /** Board slug (lowercase letters, numbers and dashes). Optional. */
5
+ board?: string
6
+ /** Accent colour as a 6-digit hex value, e.g. "#4f46e5". Optional. */
7
+ color?: string
8
+ /** Which side the launcher sits on. Optional (defaults to the widget's own default). */
9
+ position?: 'left' | 'right'
10
+ /** Greeting shown on the launcher. Optional. */
11
+ greeting?: string
12
+ }
13
+
14
+ import type { Provider } from '@angular/core'
15
+
16
+ /** Injects the widget <script> into the document once. Returns false when the key is invalid or without a DOM. */
17
+ export function injectDeskcrew(options: DeskcrewOptions): boolean
18
+ /** APP_INITIALIZER provider that injects the widget at bootstrap. */
19
+ export function provideDeskcrew(options: DeskcrewOptions): Provider
20
+ export default provideDeskcrew
21
+ export function buildTag(options: DeskcrewOptions): { tag: string | null; warnings: string[] }
package/index.js ADDED
@@ -0,0 +1,39 @@
1
+ import { APP_INITIALIZER } from '@angular/core'
2
+ import { buildAttrs } from './build-tag.js'
3
+
4
+ /** Add the widget <script> to the document once. Safe to call more than once. No-op without a DOM. */
5
+ export function injectDeskcrew(options) {
6
+ if (typeof document === 'undefined') return false
7
+ const { attrs, warnings } = buildAttrs(options)
8
+ for (const message of warnings) console.warn(message)
9
+ if (!attrs) return false
10
+ if (document.querySelector('script[src="https://deskcrew.io/desk.js"]')) return true
11
+ const s = document.createElement('script')
12
+ for (const [name, value] of attrs) {
13
+ if (name === 'src') s.src = value
14
+ else s.setAttribute(name, value)
15
+ }
16
+ s.defer = true
17
+ document.head.appendChild(s)
18
+ return true
19
+ }
20
+
21
+ /**
22
+ * providers: [provideDeskcrew({ widgetKey: 'pub_...' })] in app.config.ts
23
+ * (standalone) or in your root NgModule. Injects the widget when the app
24
+ * bootstraps in the browser; with Angular SSR the server does nothing.
25
+ *
26
+ * @param {import('./index.js').DeskcrewOptions} options
27
+ */
28
+ export function provideDeskcrew(options) {
29
+ return {
30
+ provide: APP_INITIALIZER,
31
+ multi: true,
32
+ useFactory: () => () => {
33
+ injectDeskcrew(options)
34
+ },
35
+ }
36
+ }
37
+
38
+ export default provideDeskcrew
39
+ export { buildTag } from './build-tag.js'
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@deskcrew/angular",
3
+ "version": "1.0.0",
4
+ "description": "Angular provider that adds the DeskCrew support widget (live chat, AI answers from your knowledge base, a help center) to your app at bootstrap.",
5
+ "keywords": [
6
+ "angular",
7
+ "angular2",
8
+ "ng",
9
+ "angular-library",
10
+ "standalone",
11
+ "support",
12
+ "helpdesk",
13
+ "help desk",
14
+ "customer support",
15
+ "live chat",
16
+ "chat widget",
17
+ "support widget",
18
+ "ai chat",
19
+ "ai support",
20
+ "ticketing",
21
+ "support tickets",
22
+ "knowledge base",
23
+ "deskcrew"
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/webmilmind1/angular-deskcrew.git"
28
+ },
29
+ "homepage": "https://deskcrew.io/integrations/angular",
30
+ "bugs": {
31
+ "url": "https://github.com/webmilmind1/angular-deskcrew/issues",
32
+ "email": "hello@deskcrew.io"
33
+ },
34
+ "author": "DeskCrew <hello@deskcrew.io> (https://deskcrew.io)",
35
+ "license": "MIT",
36
+ "type": "module",
37
+ "exports": {
38
+ ".": {
39
+ "types": "./index.d.ts",
40
+ "import": "./index.js",
41
+ "default": "./index.js"
42
+ }
43
+ },
44
+ "main": "index.js",
45
+ "types": "index.d.ts",
46
+ "files": [
47
+ "index.js",
48
+ "build-tag.js",
49
+ "index.d.ts",
50
+ "README.md",
51
+ "LICENSE"
52
+ ],
53
+ "engines": {
54
+ "node": ">=18"
55
+ },
56
+ "scripts": {
57
+ "test": "node --test"
58
+ },
59
+ "peerDependencies": {
60
+ "@angular/core": ">=15"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public"
64
+ }
65
+ }