commandbar 1.10.2 → 1.12.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/build/commandbar/src/shared/services/analytics/EventHandler.d.ts +9 -4
- package/build/commandbar/src/shared/services/analytics/event-queue.d.ts +13 -0
- package/build/commandbar/src/shared/services/analytics/types.d.ts +3 -3
- package/build/commandbar/src/shared/services/analytics/v2/client.d.ts +54 -0
- package/build/commandbar/src/shared/services/analytics/v2/helpers.d.ts +6 -0
- package/build/commandbar/src/shared/services/analytics/v2/schema.d.ts +152 -0
- package/build/commandbar/src/shared/services/analytics/v2/types.d.ts +4 -0
- package/build/commandbar-js/src/index.d.ts +2 -3
- package/build/commandbar-js/src/index.js +1 -1
- package/build/commandbar-js/src/snippet.d.ts +7 -1
- package/build/internal/src/client/CommandBarClientSDK.d.ts +13 -1
- package/build/internal/src/client/CommandBarProxySDK.d.ts +1 -4
- package/build/internal/src/client/CommandBarSDK.d.ts +7 -5
- package/build/internal/src/client/SDKConfig.d.ts +3 -1
- package/build/internal/src/client/globals.d.ts +1 -0
- package/build/internal/src/client/symbols.d.ts +3 -1
- package/build/internal/src/middleware/CommandFromClientV.d.ts +16 -2
- package/build/internal/src/middleware/OrganizationV.d.ts +44 -8
- package/build/internal/src/middleware/additionalResource.d.ts +9 -9
- package/build/internal/src/middleware/api.d.ts +181 -0
- package/build/internal/src/middleware/billing.d.ts +10 -0
- package/build/internal/src/middleware/chat.d.ts +3662 -172
- package/build/internal/src/middleware/checklist.d.ts +26 -10
- package/build/internal/src/middleware/command.d.ts +540 -140
- package/build/internal/src/middleware/endUser.d.ts +2 -0
- package/build/internal/src/middleware/experienceTemplate.d.ts +2882 -8
- package/build/internal/src/middleware/experiencesSearch.d.ts +233 -28
- package/build/internal/src/middleware/flags.d.ts +15 -1
- package/build/internal/src/middleware/generics.d.ts +1 -0
- package/build/internal/src/middleware/helpDocsIntegration.d.ts +98 -0
- package/build/internal/src/middleware/helpDocsSearch.d.ts +165 -20
- package/build/internal/src/middleware/helpDocsSync.d.ts +4 -0
- package/build/internal/src/middleware/helpHub.d.ts +1 -0
- package/build/internal/src/middleware/helpers/actions.d.ts +6 -6
- package/build/internal/src/middleware/helpers/commandTemplate.d.ts +2 -2
- package/build/internal/src/middleware/helpers/rules.d.ts +9 -7
- package/build/internal/src/middleware/localizedMessage.d.ts +50 -0
- package/build/internal/src/middleware/network.d.ts +1 -0
- package/build/internal/src/middleware/nudge.d.ts +104 -24
- package/build/internal/src/middleware/organization.d.ts +201 -62
- package/build/internal/src/middleware/organizationSettings.d.ts +12 -8
- package/build/internal/src/middleware/profile.d.ts +8 -0
- package/build/internal/src/middleware/recommendationSet.d.ts +18 -9
- package/build/internal/src/middleware/theme.d.ts +81 -0
- package/build/internal/src/middleware/types.d.ts +27 -6
- package/build/internal/src/middleware/user.d.ts +9 -1
- package/build/internal/src/middleware/workflow.d.ts +85 -0
- package/build/internal/src/util/sentry.d.ts +2 -2
- package/package.json +8 -3
- package/src/index.ts +2 -3
- package/src/init.ts +32 -14
- package/src/snippet.ts +84 -74
- package/build/internal/src/client/OrgConfig.d.ts +0 -5
- package/build/internal/src/middleware/guide.d.ts +0 -37
package/package.json
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "commandbar",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.12.0",
|
4
4
|
"description": "Javascript Utility for CommandBar",
|
5
5
|
"main": "build/commandbar-js/src/index.js",
|
6
6
|
"types": "build/commandbar-js/src/index.d.ts",
|
7
7
|
"sideEffects": false,
|
8
8
|
"scripts": {
|
9
9
|
"clean": "rimraf build",
|
10
|
-
"build": "NODE_ENV=production webpack build && tsc",
|
11
|
-
"minify-snippet": "
|
10
|
+
"build": "NODE_ENV=production webpack build && tsc && tsc-alias",
|
11
|
+
"minify-snippet": "tsx scripts/minify-snippet.ts",
|
12
12
|
"prepublishOnly": "yarn run clean && yarn run build",
|
13
13
|
"test": "jest --runInBand",
|
14
14
|
"test:watch": "jest --watch --verbose false --silent false",
|
@@ -23,7 +23,12 @@
|
|
23
23
|
"io-ts": "^2.2.14"
|
24
24
|
},
|
25
25
|
"devDependencies": {
|
26
|
+
"@types/jest": "^29.5.3",
|
27
|
+
"jest": "^29.7.0",
|
26
28
|
"rimraf": "3.0.2",
|
29
|
+
"tsc-alias": "^1.8.8",
|
30
|
+
"tsconfig-paths-webpack-plugin": "^4.1.0",
|
31
|
+
"tsx": "^4.9.3",
|
27
32
|
"typescript": "5.1.5",
|
28
33
|
"webpack": "^5.74.0"
|
29
34
|
}
|
package/src/index.ts
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
import Launcher, { getControlKey } from 'commandbar-launcher';
|
2
|
-
import type { CommandBarClientSDK } from '@commandbar/internal/
|
2
|
+
import type { CommandBarClientSDK } from '@commandbar/internal/client/CommandBarClientSDK';
|
3
3
|
|
4
4
|
export { default as init } from './init';
|
5
|
-
export { initProxySDK as initProxy } from '@commandbar/internal/
|
6
|
-
export { snippet } from './snippet';
|
5
|
+
export { initProxySDK as initProxy } from '@commandbar/internal/client/proxy';
|
7
6
|
export { CommandBarClientSDK };
|
8
7
|
export { Launcher, getControlKey };
|
9
8
|
|
package/src/init.ts
CHANGED
@@ -5,15 +5,19 @@ import { getProxySDK } from '../../internal/src/client/proxy';
|
|
5
5
|
import { _configuration } from '../../internal/src/client/symbols';
|
6
6
|
import { IInitOptions } from '../../internal/src/middleware/types';
|
7
7
|
|
8
|
-
const getSrc = (org: string,
|
9
|
-
let origin = 'https://api.commandbar.com';
|
8
|
+
const getSrc = (org: string, opts: IInitOptions) => {
|
9
|
+
let origin = opts.apiOrigin || 'https://api.commandbar.com';
|
10
10
|
const params = [];
|
11
11
|
|
12
12
|
const lc = localStorage.getItem('commandbar.lc');
|
13
|
-
if (lc && lc.includes('local')) {
|
13
|
+
if (lc && lc.includes('api=local')) {
|
14
14
|
// for debugging purposes
|
15
15
|
origin = 'http://localhost:8000';
|
16
16
|
}
|
17
|
+
if (lc && lc.includes('api=preview_')) {
|
18
|
+
const branchIdentifier = /api=preview_([^;$]+)/.exec(lc)?.[1];
|
19
|
+
origin = `https://${branchIdentifier}.commandbar.xyz:8000`;
|
20
|
+
}
|
17
21
|
|
18
22
|
let src = origin + '/latest/' + org;
|
19
23
|
|
@@ -21,8 +25,16 @@ const getSrc = (org: string, nonce?: string) => {
|
|
21
25
|
params.push('lc=' + lc);
|
22
26
|
}
|
23
27
|
|
24
|
-
if (nonce) {
|
25
|
-
params.push('nonce=' + encodeURIComponent(nonce));
|
28
|
+
if (opts.nonce) {
|
29
|
+
params.push('nonce=' + encodeURIComponent(opts.nonce));
|
30
|
+
}
|
31
|
+
|
32
|
+
if (opts.silentMode) {
|
33
|
+
params.push('silent=true');
|
34
|
+
}
|
35
|
+
|
36
|
+
if (opts.cdnOrigin) {
|
37
|
+
params.push('cdn=' + encodeURIComponent(opts.cdnOrigin));
|
26
38
|
}
|
27
39
|
|
28
40
|
const version = 2;
|
@@ -32,14 +44,14 @@ const getSrc = (org: string, nonce?: string) => {
|
|
32
44
|
return src;
|
33
45
|
};
|
34
46
|
|
35
|
-
const loadLatest = (org: string,
|
47
|
+
const loadLatest = (org: string, opts: IInitOptions) => {
|
36
48
|
if (document.readyState !== 'complete') {
|
37
49
|
// NOTE: `once` is not supported by IE11 and this will cause a (minor!) memory leak.
|
38
|
-
window.addEventListener('load', loadLatest.bind(null, org,
|
50
|
+
window.addEventListener('load', loadLatest.bind(null, org, opts), { capture: false, once: true });
|
39
51
|
return;
|
40
52
|
}
|
41
53
|
|
42
|
-
const src = getSrc(org,
|
54
|
+
const src = getSrc(org, opts);
|
43
55
|
|
44
56
|
const el = document.createElement('script');
|
45
57
|
el.type = 'text/javascript';
|
@@ -48,7 +60,10 @@ const loadLatest = (org: string, nonce?: string) => {
|
|
48
60
|
document.head.appendChild(el);
|
49
61
|
};
|
50
62
|
|
51
|
-
const DEFAULT_OPTS = {
|
63
|
+
const DEFAULT_OPTS = {
|
64
|
+
debug: false,
|
65
|
+
silentMode: false,
|
66
|
+
} as const;
|
52
67
|
|
53
68
|
/**
|
54
69
|
* Initializes CommandBar and injects the scripts required to load it into the <head> of the document. After calling
|
@@ -76,14 +91,17 @@ const init = (org: string, opts: IInitOptions = DEFAULT_OPTS) => {
|
|
76
91
|
config.debug && console.log('CommandBar init...', { environment: opts.environment, version: opts.version });
|
77
92
|
|
78
93
|
getProxySDK()[_configuration] = {
|
94
|
+
api: config.apiOrigin,
|
95
|
+
cdn: config.cdnOrigin,
|
79
96
|
uuid: org,
|
80
|
-
environment:
|
81
|
-
version:
|
82
|
-
config:
|
83
|
-
nonce:
|
97
|
+
environment: config.environment,
|
98
|
+
version: config.version,
|
99
|
+
config: config.config, // TODO: We should update this type to correctly reflect the structure of the response from /config/ https://cmd-k.slack.com/archives/C0315KNU7FY/p1711558822136239?thread_ts=1711554558.063509&cid=C0315KNU7FY
|
100
|
+
nonce: config.nonce,
|
101
|
+
silent: config.silentMode,
|
84
102
|
};
|
85
103
|
|
86
|
-
loadLatest(org,
|
104
|
+
loadLatest(org, config);
|
87
105
|
};
|
88
106
|
|
89
107
|
export default init;
|
package/src/snippet.ts
CHANGED
@@ -2,94 +2,104 @@
|
|
2
2
|
/* eslint-disable prefer-rest-params */
|
3
3
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-inferrable-types */
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
const org = '<org_id>';
|
6
|
+
let api = 'https://api.commandbar.com';
|
7
|
+
let cdn: string | undefined = undefined;
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
el.async = async;
|
16
|
-
el.src = src;
|
17
|
-
document.head.appendChild(el);
|
9
|
+
const polyfills = ['Object.assign', 'Symbol', 'Symbol.for'].join('%2C');
|
10
|
+
const w = window as unknown as Record<string, unknown>;
|
11
|
+
|
12
|
+
function loadScript(src: string, async = false) {
|
13
|
+
if (document.readyState !== 'complete') {
|
14
|
+
window.addEventListener('load', loadScript.bind(null, src, async), { capture: false, once: true });
|
18
15
|
}
|
16
|
+
const el = document.createElement('script');
|
17
|
+
el.type = 'text/javascript';
|
18
|
+
el.async = async;
|
19
|
+
el.src = src;
|
20
|
+
document.head.appendChild(el);
|
21
|
+
}
|
22
|
+
|
23
|
+
function bootstrap() {
|
24
|
+
if (w.CommandBar !== undefined) return;
|
25
|
+
delete w.__CommandBarBootstrap__;
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
|
27
|
+
const _configuration = Symbol.for('CommandBar::configuration');
|
28
|
+
const _disposed = Symbol.for('CommandBar::disposed');
|
29
|
+
const _isProxy = Symbol.for('CommandBar::isProxy');
|
30
|
+
const _queue = Symbol.for('CommandBar::queue');
|
31
|
+
const _unwrap = Symbol.for('CommandBar::unwrap');
|
32
|
+
const _eventSubscriptions = Symbol.for('CommandBar::eventSubscriptions');
|
23
33
|
|
24
|
-
|
25
|
-
|
26
|
-
const _disposed = Symbol.for('CommandBar::disposed');
|
27
|
-
const _isProxy = Symbol.for('CommandBar::isProxy');
|
28
|
-
const _queue = Symbol.for('CommandBar::queue');
|
29
|
-
const _unwrap = Symbol.for('CommandBar::unwrap');
|
30
|
-
const _eventSubscriptions = Symbol.for('CommandBar::eventSubscriptions');
|
34
|
+
const params = [];
|
35
|
+
const lc = localStorage.getItem('commandbar.lc');
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
if (lc && lc.includes('local')) {
|
38
|
+
api = 'http://localhost:8000';
|
39
|
+
cdn = undefined;
|
40
|
+
}
|
41
|
+
if (lc && lc.includes('api=preview_')) {
|
42
|
+
const branchIdentifier = /api=preview_([^;$]+)/.exec(lc)?.[1];
|
43
|
+
api = `https://${branchIdentifier}.commandbar.xyz:8000`;
|
44
|
+
cdn = undefined;
|
45
|
+
}
|
35
46
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
);
|
47
|
+
const proxy = Object.assign(
|
48
|
+
{
|
49
|
+
[_configuration]: { uuid: org, api, cdn },
|
50
|
+
[_disposed]: false,
|
51
|
+
[_isProxy]: true,
|
52
|
+
[_queue]: new Array<unknown>(),
|
53
|
+
[_unwrap]: () => proxy,
|
54
|
+
[_eventSubscriptions]: undefined,
|
55
|
+
},
|
56
|
+
w.CommandBar,
|
57
|
+
);
|
48
58
|
|
49
|
-
|
59
|
+
const ASYNC_METHODS_SNIPPET = ['addCommand', 'boot', 'addEventSubscriber', 'addRecordAction', 'setFormFactor'];
|
50
60
|
|
51
|
-
|
61
|
+
const sdk = proxy;
|
52
62
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
63
|
+
Object.assign(proxy, {
|
64
|
+
shareCallbacks: () => ({}),
|
65
|
+
shareContext: () => ({}),
|
66
|
+
});
|
57
67
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
return function () {
|
64
|
-
// eslint-disable-next-line prefer-rest-params
|
65
|
-
const a = Array.prototype.slice.call(arguments);
|
66
|
-
return new Promise((resolve, reject) => {
|
67
|
-
a.unshift(prop, resolve, reject);
|
68
|
-
(proxy[_queue] as Array<unknown>).push(a);
|
69
|
-
});
|
70
|
-
};
|
71
|
-
}
|
68
|
+
w.CommandBar = new Proxy(proxy, {
|
69
|
+
get: function (_, prop) {
|
70
|
+
if (prop in sdk) return proxy[prop];
|
71
|
+
if ((prop as any) === 'then') return undefined;
|
72
|
+
if (ASYNC_METHODS_SNIPPET.includes(prop as string)) {
|
72
73
|
return function () {
|
73
74
|
// eslint-disable-next-line prefer-rest-params
|
74
75
|
const a = Array.prototype.slice.call(arguments);
|
75
|
-
|
76
|
-
|
76
|
+
return new Promise((resolve, reject) => {
|
77
|
+
a.unshift(prop, resolve, reject);
|
78
|
+
(proxy[_queue] as Array<unknown>).push(a);
|
79
|
+
});
|
77
80
|
};
|
78
|
-
}
|
79
|
-
|
81
|
+
}
|
82
|
+
return function () {
|
83
|
+
// eslint-disable-next-line prefer-rest-params
|
84
|
+
const a = Array.prototype.slice.call(arguments);
|
85
|
+
a.unshift(prop);
|
86
|
+
(proxy[_queue] as Array<unknown>).push(a);
|
87
|
+
};
|
88
|
+
},
|
89
|
+
});
|
80
90
|
|
81
|
-
|
82
|
-
|
91
|
+
if (lc !== null) params.push(`lc=${lc}`);
|
92
|
+
params.push('version=2');
|
93
|
+
if (cdn) params.push(`cdn=${encodeURIComponent(cdn)}`);
|
83
94
|
|
84
|
-
|
85
|
-
|
95
|
+
loadScript(`${api}/latest/${org}?${params.join('&')}`, true);
|
96
|
+
}
|
86
97
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
};
|
98
|
+
if (typeof Object.assign === 'undefined' || typeof Symbol === 'undefined' || typeof Symbol.for === 'undefined') {
|
99
|
+
w.__CommandBarBootstrap__ = bootstrap;
|
100
|
+
loadScript(
|
101
|
+
'https://polyfill.io/v3/polyfill.min.js?version=3.101.0&callback=__CommandBarBootstrap__&features=' + polyfills,
|
102
|
+
);
|
103
|
+
} else {
|
104
|
+
bootstrap();
|
105
|
+
}
|
@@ -1,37 +0,0 @@
|
|
1
|
-
import * as t from 'io-ts';
|
2
|
-
export declare const GuideV: t.IntersectionC<[t.TypeC<{
|
3
|
-
id: t.NumberC;
|
4
|
-
organization: t.StringC;
|
5
|
-
event: t.StringC;
|
6
|
-
nudge: t.StringC;
|
7
|
-
guidance: t.StringC;
|
8
|
-
}>, t.PartialC<{}>]>;
|
9
|
-
export declare class Guide {
|
10
|
-
static create: (object: {
|
11
|
-
id: number;
|
12
|
-
organization: string;
|
13
|
-
event: string;
|
14
|
-
nudge: string;
|
15
|
-
guidance: string;
|
16
|
-
} & {}, onSuccess?: (() => void) | undefined, onError?: ((err: string) => void) | undefined) => Promise<{
|
17
|
-
id: number;
|
18
|
-
organization: string;
|
19
|
-
event: string;
|
20
|
-
nudge: string;
|
21
|
-
guidance: string;
|
22
|
-
} & {}>;
|
23
|
-
static update: (object: {
|
24
|
-
id: number;
|
25
|
-
organization: string;
|
26
|
-
event: string;
|
27
|
-
nudge: string;
|
28
|
-
guidance: string;
|
29
|
-
} & {}, onSuccess?: (() => void) | undefined, onError?: ((err: string) => void) | undefined) => Promise<{
|
30
|
-
id: number;
|
31
|
-
organization: string;
|
32
|
-
event: string;
|
33
|
-
nudge: string;
|
34
|
-
guidance: string;
|
35
|
-
} & {}>;
|
36
|
-
static delete: (id: string | number, params?: Record<string, string> | undefined, onSuccess?: (() => void) | undefined, onError?: ((err: string) => void) | undefined) => Promise<void>;
|
37
|
-
}
|