commandbar 1.10.0 → 1.10.2-alpha
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 +7 -2
- package/build/commandbar/src/shared/services/analytics/event-queue.d.ts +13 -0
- package/build/commandbar/src/shared/services/analytics/types.d.ts +1 -1
- 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 +0 -1
- 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 +12 -0
- package/build/internal/src/client/CommandBarProxySDK.d.ts +1 -4
- package/build/internal/src/client/CommandBarSDK.d.ts +8 -4
- 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 +5 -1
- package/build/internal/src/middleware/CommandFromClientV.d.ts +16 -2
- package/build/internal/src/middleware/OrganizationV.d.ts +42 -16
- package/build/internal/src/middleware/additionalResource.d.ts +9 -9
- package/build/internal/src/middleware/api.d.ts +173 -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 +18 -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 +2874 -8
- package/build/internal/src/middleware/experiencesSearch.d.ts +233 -28
- package/build/internal/src/middleware/flags.d.ts +14 -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/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 +7 -7
- package/build/internal/src/middleware/localizedMessage.d.ts +50 -0
- package/build/internal/src/middleware/network.d.ts +8 -1
- package/build/internal/src/middleware/nudge.d.ts +96 -24
- package/build/internal/src/middleware/organization.d.ts +196 -78
- package/build/internal/src/middleware/organizationSettings.d.ts +8 -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 +73 -60
- package/build/internal/src/middleware/types.d.ts +25 -6
- package/build/internal/src/middleware/user.d.ts +9 -1
- package/build/internal/src/middleware/workflow.d.ts +69 -0
- package/package.json +5 -2
- package/src/index.ts +0 -1
- package/src/init.ts +27 -12
- package/src/snippet.ts +79 -74
- package/build/internal/src/client/OrgConfig.d.ts +0 -5
- package/build/internal/src/middleware/guide.d.ts +0 -37
@@ -11,13 +11,12 @@ import { OrganizationStatusV, KeyEventV, RecordSettingsByContextKeyV, InternalSe
|
|
11
11
|
import { OrganizationSettingsV } from './organizationSettings';
|
12
12
|
import { UserV } from './user';
|
13
13
|
import { ContextV } from './context';
|
14
|
-
import { GuideV } from './guide';
|
15
14
|
import { HistoryEventV } from './historyEvent';
|
16
15
|
import { HelpDocSyncLogMessageV, HelpDocsSyncV } from './helpDocsSync';
|
17
16
|
import { HelpDocsIntegrationV } from './helpDocsIntegration';
|
18
17
|
import { EndUserStoreDataV, EndUserV, NudgeInteractionStateV, NudgeInteractionsV, ChecklistInteractionStateV, ChecklistInteractionsV, DecideResponseV } from './endUser';
|
19
18
|
import { SkinV } from './skin';
|
20
|
-
import { ThemeV, ThemeV2V } from './theme';
|
19
|
+
import { ThemeV, ThemeV2V, ThemeModeV } from './theme';
|
21
20
|
import { ProfileV } from './profile';
|
22
21
|
import { PlaceholderV } from './placeholder';
|
23
22
|
import { EnvReleaseInfoV, ReleaseStepV, ReleaseV } from './releases';
|
@@ -32,7 +31,7 @@ import { AudienceV } from './helpers/audience';
|
|
32
31
|
import { AdditionalResourceV } from './additionalResource';
|
33
32
|
import { RecommendationSetV } from './recommendationSet';
|
34
33
|
import { BillingProfileV, UsageV } from './billing';
|
35
|
-
import { UserMessageV, AIMessageV, MessageV, AIAnswerPayloadV, AIAnswerV, ContinuationsPayloadV, ContinuationV, CreateAnswerFeedbackPayloadV, QuestionSuggestionsPayloadV, QuestionSuggestionsV, ExperienceV, CreateChatPayloadV, ChatV, CopilotSettingsPreviewV } from './chat';
|
34
|
+
import { UserMessageV, AIMessageV, AIMessageExtraV, MessageV, AIAnswerPayloadV, AIAnswerV, ContinuationsPayloadV, ContinuationV, CreateAnswerFeedbackPayloadV, QuestionSuggestionsPayloadV, QuestionSuggestionsV, ExperienceV, CreateChatPayloadV, ChatV, CopilotSettingsPreviewV, HandoffPayloadV, ExternalChatPayloadV, ExternalChatHistoryV } from './chat';
|
36
35
|
import { HelpDocHitV, SearchHelpDocsPayloadV, SearchHelpDocsResponseV } from './helpDocsSearch';
|
37
36
|
import { ExperienceHitV, ExperienceTypeOptions, SearchExperiencesPayloadV, SearchExperiencesResponseV } from './experiencesSearch';
|
38
37
|
import { HelpHubLauncherSettingsV } from './helpHub';
|
@@ -40,13 +39,19 @@ import { EntityChangeV } from './entityChanges';
|
|
40
39
|
import { Flags } from './flags';
|
41
40
|
import { CopilotPersonalityAdjectiveV, CopilotPersonalityResponseFormatV, CopilotPersonalityResponseLengthV, CopilotPersonalityV } from './helpers/copilotPersonality';
|
42
41
|
import { ExperienceTemplateV } from './experienceTemplate';
|
42
|
+
import { APIV } from './api';
|
43
|
+
import { LocalizedMessagePatchV, LocalizedMessageV, LocalizedMessages } from './localizedMessage';
|
44
|
+
import { WorkflowV } from './workflow';
|
43
45
|
/*******************************************************************************/
|
44
46
|
export type IInitOptions = {
|
47
|
+
apiOrigin?: string;
|
48
|
+
cdnOrigin?: string;
|
45
49
|
debug?: boolean;
|
46
50
|
environment?: string;
|
47
51
|
version?: string;
|
48
52
|
config?: any;
|
49
53
|
nonce?: string;
|
54
|
+
silentMode?: boolean;
|
50
55
|
};
|
51
56
|
/** Additional foobar init options */
|
52
57
|
export declare const SUPPORTED_FOOBAR_INIT_DEPLOYMENT_OPTIONS: readonly ["dev", "labs", "prod"];
|
@@ -63,9 +68,6 @@ export type IEditorCommandTypeLite = t.TypeOf<typeof EditorCommandLiteV> & unkno
|
|
63
68
|
export type ICommandTypeLite = t.TypeOf<typeof CommandLiteV> & unknown;
|
64
69
|
export type { ICommandFromClientType } from './ICommandFromClientType';
|
65
70
|
export type ICommandCategoryType = t.TypeOf<typeof CommandCategoryV> & unknown;
|
66
|
-
export type IGuideType = t.TypeOf<typeof GuideV> & {
|
67
|
-
preview?: boolean;
|
68
|
-
} & unknown;
|
69
71
|
export type IHistoryEventType = t.TypeOf<typeof HistoryEventV> & unknown;
|
70
72
|
export type IEntityChangeType = t.TypeOf<typeof EntityChangeV> & unknown;
|
71
73
|
export type IHelpDocsSyncType = t.TypeOf<typeof HelpDocsSyncV> & unknown;
|
@@ -78,6 +80,7 @@ export type IInternalSettingsType = t.TypeOf<typeof InternalSettingsV> & unknown
|
|
78
80
|
export type ISkinType = t.TypeOf<typeof SkinV> & unknown;
|
79
81
|
export type IThemeType = t.TypeOf<typeof ThemeV> & unknown;
|
80
82
|
export type IThemeV2Type = t.TypeOf<typeof ThemeV2V> & unknown;
|
83
|
+
export type IThemeModeType = t.TypeOf<typeof ThemeModeV> & unknown;
|
81
84
|
export type IProfileType = t.TypeOf<typeof ProfileV> & unknown;
|
82
85
|
export type IOrganizationSettingsType = t.TypeOf<typeof OrganizationSettingsV> & unknown;
|
83
86
|
export type IPlaceholderType = t.TypeOf<typeof PlaceholderV> & unknown;
|
@@ -123,6 +126,12 @@ export type INudgeTooltipStepType = INudgeStepType & {
|
|
123
126
|
type: 'tooltip';
|
124
127
|
};
|
125
128
|
};
|
129
|
+
export type INudgePinStepType = INudgeStepType & {
|
130
|
+
form_factor: {
|
131
|
+
type: 'pin';
|
132
|
+
};
|
133
|
+
};
|
134
|
+
export type INudgeAnchorableStepType = INudgeTooltipStepType | INudgePinStepType;
|
126
135
|
export type INudgeStepContentBlockType = t.TypeOf<typeof NudgeContentBlockV> & unknown;
|
127
136
|
export type INudgeStepContentMarkdownBlockType = t.TypeOf<typeof NudgeContentMarkdownBlockV> & unknown;
|
128
137
|
export type INudgeStepContentImageBlockType = t.TypeOf<typeof NudgeContentImageBlockV> & unknown;
|
@@ -166,6 +175,7 @@ export type NudgeInteractions = t.TypeOf<typeof NudgeInteractionsV> & unknown;
|
|
166
175
|
export type IMessageType = t.TypeOf<typeof MessageV> & unknown;
|
167
176
|
export type IUserMessageType = t.TypeOf<typeof UserMessageV> & unknown;
|
168
177
|
export type IAIMessageType = t.TypeOf<typeof AIMessageV> & unknown;
|
178
|
+
export type IAIMessageExtraType = t.TypeOf<typeof AIMessageExtraV> & unknown;
|
169
179
|
export type IQuestionSuggestionsType = t.TypeOf<typeof QuestionSuggestionsV> & unknown;
|
170
180
|
export type IQuestionSuggestionsPayloadType = t.TypeOf<typeof QuestionSuggestionsPayloadV> & unknown;
|
171
181
|
export type ICreateChatPayloadType = t.TypeOf<typeof CreateChatPayloadV> & unknown;
|
@@ -174,6 +184,9 @@ export type IExperienceType = t.TypeOf<typeof ExperienceV> & unknown;
|
|
174
184
|
export type IContinuationsPayloadType = t.TypeOf<typeof ContinuationsPayloadV> & unknown;
|
175
185
|
export type IAIAnswerType = t.TypeOf<typeof AIAnswerV> & unknown;
|
176
186
|
export type IAIAnswerPayloadType = t.TypeOf<typeof AIAnswerPayloadV> & unknown;
|
187
|
+
export type IHandoffPayloadType = t.TypeOf<typeof HandoffPayloadV> & unknown;
|
188
|
+
export type IExternalChatPayloadType = t.TypeOf<typeof ExternalChatPayloadV> & unknown;
|
189
|
+
export type IExternalChatHistoryType = t.TypeOf<typeof ExternalChatHistoryV> & unknown;
|
177
190
|
export type ICreateAnswerFeedbackPayloadType = t.TypeOf<typeof CreateAnswerFeedbackPayloadV> & unknown;
|
178
191
|
export type ISearchHelpDocsPayloadType = t.TypeOf<typeof SearchHelpDocsPayloadV> & unknown;
|
179
192
|
export type ISearchHelpDocsResponseType = t.TypeOf<typeof SearchHelpDocsResponseV> & unknown;
|
@@ -229,6 +242,10 @@ export interface IResourceType extends IUserContext {
|
|
229
242
|
}
|
230
243
|
export type IAdditionalResource = t.TypeOf<typeof AdditionalResourceV> & unknown;
|
231
244
|
export type IRecommendationSet = t.TypeOf<typeof RecommendationSetV> & unknown;
|
245
|
+
export type ILocalizedMessage = t.TypeOf<typeof LocalizedMessageV> & unknown;
|
246
|
+
export type ILocalizedMessagePatch = t.TypeOf<typeof LocalizedMessagePatchV> & unknown;
|
247
|
+
export type IAPI = t.TypeOf<typeof APIV> & unknown;
|
248
|
+
export type IWorkflow = t.TypeOf<typeof WorkflowV> & unknown;
|
232
249
|
export type IConfigEndpointResponse = {
|
233
250
|
commands: any[];
|
234
251
|
categories: any[];
|
@@ -244,6 +261,7 @@ export type IConfigEndpointResponse = {
|
|
244
261
|
__meta__?: {
|
245
262
|
latest_foobar_version?: string;
|
246
263
|
};
|
264
|
+
localized_messages: LocalizedMessages;
|
247
265
|
};
|
248
266
|
export type IConfigType = {
|
249
267
|
commands: ICommandType[];
|
@@ -260,6 +278,7 @@ export type IConfigType = {
|
|
260
278
|
latest_foobar_version?: string;
|
261
279
|
};
|
262
280
|
flags: Flags;
|
281
|
+
localized_messages: LocalizedMessages;
|
263
282
|
};
|
264
283
|
export type { IRecordSettings } from './IRecordSettings';
|
265
284
|
export type IRecordSettingsByContextKey = t.TypeOf<typeof RecordSettingsByContextKeyV> & unknown;
|
@@ -7,7 +7,15 @@ export declare const UserV: t.IntersectionC<[t.TypeC<{
|
|
7
7
|
organization: t.StringC;
|
8
8
|
organization_name: t.StringC;
|
9
9
|
api_token: t.UnionC<[t.StringC, t.NullC]>;
|
10
|
-
profile: t.
|
10
|
+
profile: t.TypeC<{
|
11
|
+
user: t.StringC;
|
12
|
+
organization: t.StringC;
|
13
|
+
is_active: t.BooleanC;
|
14
|
+
role: t.UnionC<[t.LiteralC<"admin">, t.LiteralC<"editor">, t.LiteralC<"contributor">, t.LiteralC<"viewer">]>;
|
15
|
+
first_name: t.StringC;
|
16
|
+
last_name: t.StringC;
|
17
|
+
email: t.StringC;
|
18
|
+
}>;
|
11
19
|
has_updated_password: t.BooleanC;
|
12
20
|
is_active: t.BooleanC;
|
13
21
|
is_hijacked: t.BooleanC;
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import * as t from 'io-ts';
|
2
|
+
export declare const WorkflowV: t.TypeC<{
|
3
|
+
id: t.NumberC;
|
4
|
+
archived: t.BooleanC;
|
5
|
+
is_live: t.BooleanC;
|
6
|
+
title: t.StringC;
|
7
|
+
prompt: t.StringC;
|
8
|
+
trigger: t.AnyC;
|
9
|
+
}>;
|
10
|
+
export declare class Workflow {
|
11
|
+
static decode: (data: any) => {
|
12
|
+
id: number;
|
13
|
+
archived: boolean;
|
14
|
+
is_live: boolean;
|
15
|
+
title: string;
|
16
|
+
prompt: string;
|
17
|
+
trigger: any;
|
18
|
+
};
|
19
|
+
static create: (object: {
|
20
|
+
id: number;
|
21
|
+
archived: boolean;
|
22
|
+
is_live: boolean;
|
23
|
+
title: string;
|
24
|
+
prompt: string;
|
25
|
+
trigger: any;
|
26
|
+
}, onSuccess?: (() => void) | undefined, onError?: ((err: string) => void) | undefined) => Promise<{
|
27
|
+
id: number;
|
28
|
+
archived: boolean;
|
29
|
+
is_live: boolean;
|
30
|
+
title: string;
|
31
|
+
prompt: string;
|
32
|
+
trigger: any;
|
33
|
+
}>;
|
34
|
+
static update: (object: {
|
35
|
+
id: number;
|
36
|
+
archived: boolean;
|
37
|
+
is_live: boolean;
|
38
|
+
title: string;
|
39
|
+
prompt: string;
|
40
|
+
trigger: any;
|
41
|
+
}, onSuccess?: (() => void) | undefined, onError?: ((err: string) => void) | undefined) => Promise<{
|
42
|
+
id: number;
|
43
|
+
archived: boolean;
|
44
|
+
is_live: boolean;
|
45
|
+
title: string;
|
46
|
+
prompt: string;
|
47
|
+
trigger: any;
|
48
|
+
}>;
|
49
|
+
static delete: (id: string | number, params?: Record<string, string> | undefined, onSuccess?: (() => void) | undefined, onError?: ((err: string) => void) | undefined) => Promise<void>;
|
50
|
+
static list: (onSuccess?: (() => void) | undefined, onError?: ((err: string) => void) | undefined) => Promise<{
|
51
|
+
id: number;
|
52
|
+
archived: boolean;
|
53
|
+
is_live: boolean;
|
54
|
+
title: string;
|
55
|
+
prompt: string;
|
56
|
+
trigger: any;
|
57
|
+
}[]>;
|
58
|
+
static read: (arg0: string, params?: Record<string, string> | undefined, callbacks?: {
|
59
|
+
onSuccess?: (() => void) | undefined;
|
60
|
+
onError?: ((err: string) => void) | undefined;
|
61
|
+
} | undefined) => Promise<{
|
62
|
+
id: number;
|
63
|
+
archived: boolean;
|
64
|
+
is_live: boolean;
|
65
|
+
title: string;
|
66
|
+
prompt: string;
|
67
|
+
trigger: any;
|
68
|
+
}>;
|
69
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "commandbar",
|
3
|
-
"version": "1.10.
|
3
|
+
"version": "1.10.2-alpha",
|
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",
|
@@ -8,7 +8,7 @@
|
|
8
8
|
"scripts": {
|
9
9
|
"clean": "rimraf build",
|
10
10
|
"build": "NODE_ENV=production webpack build && tsc",
|
11
|
-
"minify-snippet": "
|
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,10 @@
|
|
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
|
+
"tsx": "^4.9.3",
|
27
30
|
"typescript": "5.1.5",
|
28
31
|
"webpack": "^5.74.0"
|
29
32
|
}
|
package/src/index.ts
CHANGED
@@ -3,7 +3,6 @@ import type { CommandBarClientSDK } from '@commandbar/internal/src/client/Comman
|
|
3
3
|
|
4
4
|
export { default as init } from './init';
|
5
5
|
export { initProxySDK as initProxy } from '@commandbar/internal/src/client/proxy';
|
6
|
-
export { snippet } from './snippet';
|
7
6
|
export { CommandBarClientSDK };
|
8
7
|
export { Launcher, getControlKey };
|
9
8
|
|
package/src/init.ts
CHANGED
@@ -5,8 +5,8 @@ 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');
|
@@ -21,8 +21,16 @@ const getSrc = (org: string, nonce?: string) => {
|
|
21
21
|
params.push('lc=' + lc);
|
22
22
|
}
|
23
23
|
|
24
|
-
if (nonce) {
|
25
|
-
params.push('nonce=' + nonce);
|
24
|
+
if (opts.nonce) {
|
25
|
+
params.push('nonce=' + encodeURIComponent(opts.nonce));
|
26
|
+
}
|
27
|
+
|
28
|
+
if (opts.silentMode) {
|
29
|
+
params.push('silent=true');
|
30
|
+
}
|
31
|
+
|
32
|
+
if (opts.cdnOrigin) {
|
33
|
+
params.push('cdn=' + encodeURIComponent(opts.cdnOrigin));
|
26
34
|
}
|
27
35
|
|
28
36
|
const version = 2;
|
@@ -32,14 +40,14 @@ const getSrc = (org: string, nonce?: string) => {
|
|
32
40
|
return src;
|
33
41
|
};
|
34
42
|
|
35
|
-
const loadLatest = (org: string,
|
43
|
+
const loadLatest = (org: string, opts: IInitOptions) => {
|
36
44
|
if (document.readyState !== 'complete') {
|
37
45
|
// NOTE: `once` is not supported by IE11 and this will cause a (minor!) memory leak.
|
38
|
-
window.addEventListener('load', loadLatest.bind(null, org,
|
46
|
+
window.addEventListener('load', loadLatest.bind(null, org, opts), { capture: false, once: true });
|
39
47
|
return;
|
40
48
|
}
|
41
49
|
|
42
|
-
const src = getSrc(org,
|
50
|
+
const src = getSrc(org, opts);
|
43
51
|
|
44
52
|
const el = document.createElement('script');
|
45
53
|
el.type = 'text/javascript';
|
@@ -48,7 +56,10 @@ const loadLatest = (org: string, nonce?: string) => {
|
|
48
56
|
document.head.appendChild(el);
|
49
57
|
};
|
50
58
|
|
51
|
-
const DEFAULT_OPTS = {
|
59
|
+
const DEFAULT_OPTS = {
|
60
|
+
debug: false,
|
61
|
+
silentMode: false,
|
62
|
+
} as const;
|
52
63
|
|
53
64
|
/**
|
54
65
|
* Initializes CommandBar and injects the scripts required to load it into the <head> of the document. After calling
|
@@ -76,13 +87,17 @@ const init = (org: string, opts: IInitOptions = DEFAULT_OPTS) => {
|
|
76
87
|
config.debug && console.log('CommandBar init...', { environment: opts.environment, version: opts.version });
|
77
88
|
|
78
89
|
getProxySDK()[_configuration] = {
|
90
|
+
api: config.apiOrigin,
|
91
|
+
cdn: config.cdnOrigin,
|
79
92
|
uuid: org,
|
80
|
-
environment:
|
81
|
-
version:
|
82
|
-
config:
|
93
|
+
environment: config.environment,
|
94
|
+
version: config.version,
|
95
|
+
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
|
96
|
+
nonce: config.nonce,
|
97
|
+
silent: config.silentMode,
|
83
98
|
};
|
84
99
|
|
85
|
-
loadLatest(org,
|
100
|
+
loadLatest(org, config);
|
86
101
|
};
|
87
102
|
|
88
103
|
export default init;
|
package/src/snippet.ts
CHANGED
@@ -2,94 +2,99 @@
|
|
2
2
|
/* eslint-disable prefer-rest-params */
|
3
3
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-inferrable-types */
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
let 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
|
+
}
|
35
41
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
);
|
42
|
+
const proxy = Object.assign(
|
43
|
+
{
|
44
|
+
[_configuration]: { uuid: org, api, cdn },
|
45
|
+
[_disposed]: false,
|
46
|
+
[_isProxy]: true,
|
47
|
+
[_queue]: new Array<unknown>(),
|
48
|
+
[_unwrap]: () => proxy,
|
49
|
+
[_eventSubscriptions]: undefined,
|
50
|
+
},
|
51
|
+
w.CommandBar,
|
52
|
+
);
|
48
53
|
|
49
|
-
|
54
|
+
const ASYNC_METHODS_SNIPPET = ['addCommand', 'boot', 'addEventSubscriber', 'addRecordAction', 'setFormFactor'];
|
50
55
|
|
51
|
-
|
56
|
+
const sdk = proxy;
|
52
57
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
58
|
+
Object.assign(proxy, {
|
59
|
+
shareCallbacks: () => ({}),
|
60
|
+
shareContext: () => ({}),
|
61
|
+
});
|
57
62
|
|
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
|
-
}
|
63
|
+
w.CommandBar = new Proxy(proxy, {
|
64
|
+
get: function (_, prop) {
|
65
|
+
if (prop in sdk) return proxy[prop];
|
66
|
+
if ((prop as any) === 'then') return undefined;
|
67
|
+
if (ASYNC_METHODS_SNIPPET.includes(prop as string)) {
|
72
68
|
return function () {
|
73
69
|
// eslint-disable-next-line prefer-rest-params
|
74
70
|
const a = Array.prototype.slice.call(arguments);
|
75
|
-
|
76
|
-
|
71
|
+
return new Promise((resolve, reject) => {
|
72
|
+
a.unshift(prop, resolve, reject);
|
73
|
+
(proxy[_queue] as Array<unknown>).push(a);
|
74
|
+
});
|
77
75
|
};
|
78
|
-
}
|
79
|
-
|
76
|
+
}
|
77
|
+
return function () {
|
78
|
+
// eslint-disable-next-line prefer-rest-params
|
79
|
+
const a = Array.prototype.slice.call(arguments);
|
80
|
+
a.unshift(prop);
|
81
|
+
(proxy[_queue] as Array<unknown>).push(a);
|
82
|
+
};
|
83
|
+
},
|
84
|
+
});
|
80
85
|
|
81
|
-
|
82
|
-
|
86
|
+
if (lc !== null) params.push(`lc=${lc}`);
|
87
|
+
params.push('version=2');
|
88
|
+
if (cdn) params.push(`cdn=${encodeURIComponent(cdn)}`);
|
83
89
|
|
84
|
-
|
85
|
-
|
90
|
+
loadScript(`${api}/latest/${org}?${params.join('&')}`, true);
|
91
|
+
}
|
86
92
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
};
|
93
|
+
if (typeof Object.assign === 'undefined' || typeof Symbol === 'undefined' || typeof Symbol.for === 'undefined') {
|
94
|
+
w.__CommandBarBootstrap__ = bootstrap;
|
95
|
+
loadScript(
|
96
|
+
'https://polyfill.io/v3/polyfill.min.js?version=3.101.0&callback=__CommandBarBootstrap__&features=' + polyfills,
|
97
|
+
);
|
98
|
+
} else {
|
99
|
+
bootstrap();
|
100
|
+
}
|
@@ -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
|
-
}
|