workwonders-sdk 0.0.1
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/.dockerignore +1 -0
- package/.env.example +2 -0
- package/Dockerfile +17 -0
- package/README.md +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/types/changelogContextConditionsDto.d.ts +16 -0
- package/dist/types/changelogContextConditionsDto.d.ts.map +1 -0
- package/dist/types/changelogContextConditionsDto.js +2 -0
- package/dist/types/changelogContextConditionsDto.js.map +1 -0
- package/dist/types/changelogContextConditionsDtoAND.d.ts +10 -0
- package/dist/types/changelogContextConditionsDtoAND.d.ts.map +1 -0
- package/dist/types/changelogContextConditionsDtoAND.js +8 -0
- package/dist/types/changelogContextConditionsDtoAND.js.map +1 -0
- package/dist/types/changelogContextConditionsDtoNOT.d.ts +10 -0
- package/dist/types/changelogContextConditionsDtoNOT.d.ts.map +1 -0
- package/dist/types/changelogContextConditionsDtoNOT.js +8 -0
- package/dist/types/changelogContextConditionsDtoNOT.js.map +1 -0
- package/dist/types/changelogContextConditionsDtoORItem.d.ts +10 -0
- package/dist/types/changelogContextConditionsDtoORItem.d.ts.map +1 -0
- package/dist/types/changelogContextConditionsDtoORItem.js +8 -0
- package/dist/types/changelogContextConditionsDtoORItem.js.map +1 -0
- package/dist/types/changelogSummaryDto.d.ts +23 -0
- package/dist/types/changelogSummaryDto.d.ts.map +1 -0
- package/dist/types/changelogSummaryDto.js +2 -0
- package/dist/types/changelogSummaryDto.js.map +1 -0
- package/dist/types/changelogSummaryDtoShowMode.d.ts +12 -0
- package/dist/types/changelogSummaryDtoShowMode.d.ts.map +1 -0
- package/dist/types/changelogSummaryDtoShowMode.js +12 -0
- package/dist/types/changelogSummaryDtoShowMode.js.map +1 -0
- package/dist/types/organizationChangelogConfigDto.d.ts +11 -0
- package/dist/types/organizationChangelogConfigDto.d.ts.map +1 -0
- package/dist/types/organizationChangelogConfigDto.js +8 -0
- package/dist/types/organizationChangelogConfigDto.js.map +1 -0
- package/dist/types/organizationDto.d.ts +55 -0
- package/dist/types/organizationDto.d.ts.map +1 -0
- package/dist/types/organizationDto.js +2 -0
- package/dist/types/organizationDto.js.map +1 -0
- package/dist/types/organizationDtoAccessLevel.d.ts +15 -0
- package/dist/types/organizationDtoAccessLevel.d.ts.map +1 -0
- package/dist/types/organizationDtoAccessLevel.js +12 -0
- package/dist/types/organizationDtoAccessLevel.js.map +1 -0
- package/dist/types/organizationDtoEnabledModulesItem.d.ts +14 -0
- package/dist/types/organizationDtoEnabledModulesItem.d.ts.map +1 -0
- package/dist/types/organizationDtoEnabledModulesItem.js +14 -0
- package/dist/types/organizationDtoEnabledModulesItem.js.map +1 -0
- package/dist/types/organizationDtoRole.d.ts +16 -0
- package/dist/types/organizationDtoRole.d.ts.map +1 -0
- package/dist/types/organizationDtoRole.js +13 -0
- package/dist/types/organizationDtoRole.js.map +1 -0
- package/dist/types/organizationDtoTheme.d.ts +15 -0
- package/dist/types/organizationDtoTheme.d.ts.map +1 -0
- package/dist/types/organizationDtoTheme.js +12 -0
- package/dist/types/organizationDtoTheme.js.map +1 -0
- package/dist/types/organizationFeaturesDto.d.ts +18 -0
- package/dist/types/organizationFeaturesDto.d.ts.map +1 -0
- package/dist/types/organizationFeaturesDto.js +8 -0
- package/dist/types/organizationFeaturesDto.js.map +1 -0
- package/dist/types/organizationFeedbackPostConfigDto.d.ts +14 -0
- package/dist/types/organizationFeedbackPostConfigDto.d.ts.map +1 -0
- package/dist/types/organizationFeedbackPostConfigDto.js +2 -0
- package/dist/types/organizationFeedbackPostConfigDto.js.map +1 -0
- package/dist/types/organizationFeedbackPostConfigDtoCopywriting.d.ts +11 -0
- package/dist/types/organizationFeedbackPostConfigDtoCopywriting.d.ts.map +1 -0
- package/dist/types/organizationFeedbackPostConfigDtoCopywriting.js +2 -0
- package/dist/types/organizationFeedbackPostConfigDtoCopywriting.js.map +1 -0
- package/dist/types/organizationFeedbackPostCopywritingDto.d.ts +13 -0
- package/dist/types/organizationFeedbackPostCopywritingDto.d.ts.map +1 -0
- package/dist/types/organizationFeedbackPostCopywritingDto.js +8 -0
- package/dist/types/organizationFeedbackPostCopywritingDto.js.map +1 -0
- package/dist/workwonders-sdk.d.ts +31 -0
- package/dist/workwonders-sdk.d.ts.map +1 -0
- package/dist/workwonders-sdk.js +265 -0
- package/dist/workwonders-sdk.js.map +1 -0
- package/docker-compose.yml +15 -0
- package/index.html +51 -0
- package/package.json +20 -0
- package/public/_headers +4 -0
- package/public/style.css +78 -0
- package/public/ww.png +0 -0
- package/src/index.ts +80 -0
- package/src/types/changelogContextConditionsDto.ts +16 -0
- package/src/types/changelogContextConditionsDtoAND.ts +8 -0
- package/src/types/changelogContextConditionsDtoNOT.ts +8 -0
- package/src/types/changelogContextConditionsDtoORItem.ts +8 -0
- package/src/types/changelogSummaryDto.ts +24 -0
- package/src/types/changelogSummaryDtoShowMode.ts +15 -0
- package/src/types/organizationChangelogConfigDto.ts +12 -0
- package/src/types/organizationDto.ts +56 -0
- package/src/types/organizationDtoAccessLevel.ts +18 -0
- package/src/types/organizationDtoEnabledModulesItem.ts +17 -0
- package/src/types/organizationDtoRole.ts +21 -0
- package/src/types/organizationDtoTheme.ts +18 -0
- package/src/types/organizationFeaturesDto.ts +18 -0
- package/src/types/organizationFeedbackPostConfigDto.ts +14 -0
- package/src/types/organizationFeedbackPostConfigDtoCopywriting.ts +11 -0
- package/src/types/organizationFeedbackPostCopywritingDto.ts +13 -0
- package/src/vite-env.d.ts +11 -0
- package/src/workwonders-sdk.ts +417 -0
- package/tsconfig.json +29 -0
- package/vite.config.ts +14 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
import type { ChangelogSummaryDtoShowMode } from "./changelogSummaryDtoShowMode";
|
|
8
|
+
import type { ChangelogContextConditionsDto } from "./changelogContextConditionsDto";
|
|
9
|
+
|
|
10
|
+
export interface ChangelogSummaryDto {
|
|
11
|
+
showMode: ChangelogSummaryDtoShowMode;
|
|
12
|
+
/** The ID of the changelog */
|
|
13
|
+
id: number;
|
|
14
|
+
/** The date and time the changelog was created */
|
|
15
|
+
createdAt: string;
|
|
16
|
+
/** The date and time the changelog was updated */
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
/** The changelog translations */
|
|
19
|
+
availableLanguages: string[];
|
|
20
|
+
/** @nullable */
|
|
21
|
+
publishedAt: string | null;
|
|
22
|
+
contextConditions: ChangelogContextConditionsDto;
|
|
23
|
+
}
|
|
24
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type ChangelogSummaryDtoShowMode =
|
|
9
|
+
(typeof ChangelogSummaryDtoShowMode)[keyof typeof ChangelogSummaryDtoShowMode];
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
12
|
+
export const ChangelogSummaryDtoShowMode = {
|
|
13
|
+
Regular: 'Regular',
|
|
14
|
+
ContextBased: 'ContextBased',
|
|
15
|
+
} as const;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface OrganizationChangelogConfigDto {
|
|
9
|
+
disableCollaboration: boolean;
|
|
10
|
+
showLatestChangelogOnFirstVisit: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
import type { OrganizationDtoAccessLevel } from "./organizationDtoAccessLevel";
|
|
8
|
+
import type { OrganizationDtoRole } from "./organizationDtoRole";
|
|
9
|
+
import type { OrganizationDtoTheme } from "./organizationDtoTheme";
|
|
10
|
+
import type { OrganizationDtoEnabledModulesItem } from "./organizationDtoEnabledModulesItem";
|
|
11
|
+
import type { OrganizationChangelogConfigDto } from "./organizationChangelogConfigDto";
|
|
12
|
+
import type { OrganizationFeedbackPostConfigDto } from "./organizationFeedbackPostConfigDto";
|
|
13
|
+
import type { OrganizationFeaturesDto } from "./organizationFeaturesDto";
|
|
14
|
+
|
|
15
|
+
export interface OrganizationDto {
|
|
16
|
+
/** Whether organization is public or private */
|
|
17
|
+
accessLevel: OrganizationDtoAccessLevel;
|
|
18
|
+
/** @nullable */
|
|
19
|
+
role: OrganizationDtoRole;
|
|
20
|
+
/** The theme of the organization */
|
|
21
|
+
theme: OrganizationDtoTheme;
|
|
22
|
+
/** Array of enabled module types */
|
|
23
|
+
enabledModules: OrganizationDtoEnabledModulesItem[];
|
|
24
|
+
/** The organization id */
|
|
25
|
+
id: number;
|
|
26
|
+
/** The organization name */
|
|
27
|
+
name: string;
|
|
28
|
+
/**
|
|
29
|
+
* The organization website url
|
|
30
|
+
* @nullable
|
|
31
|
+
*/
|
|
32
|
+
websiteUrl: string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Company SSO URL
|
|
35
|
+
* @nullable
|
|
36
|
+
*/
|
|
37
|
+
ssoUrl: string | null;
|
|
38
|
+
/** The organization slug */
|
|
39
|
+
slug: string;
|
|
40
|
+
/** The languages of the organization */
|
|
41
|
+
languages: string[];
|
|
42
|
+
/** The default language of the organization */
|
|
43
|
+
defaultLanguage: string;
|
|
44
|
+
/**
|
|
45
|
+
* The logo URL of the organization
|
|
46
|
+
* @nullable
|
|
47
|
+
*/
|
|
48
|
+
logoUrl: string | null;
|
|
49
|
+
primaryColor: string;
|
|
50
|
+
backgroundColor: string;
|
|
51
|
+
changelogConfig: OrganizationChangelogConfigDto;
|
|
52
|
+
feedbackPostConfig: OrganizationFeedbackPostConfigDto;
|
|
53
|
+
features: OrganizationFeaturesDto;
|
|
54
|
+
removeWorkWondersBranding: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Whether organization is public or private
|
|
10
|
+
*/
|
|
11
|
+
export type OrganizationDtoAccessLevel =
|
|
12
|
+
(typeof OrganizationDtoAccessLevel)[keyof typeof OrganizationDtoAccessLevel];
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
15
|
+
export const OrganizationDtoAccessLevel = {
|
|
16
|
+
Public: 'Public',
|
|
17
|
+
Private: 'Private',
|
|
18
|
+
} as const;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type OrganizationDtoEnabledModulesItem =
|
|
9
|
+
(typeof OrganizationDtoEnabledModulesItem)[keyof typeof OrganizationDtoEnabledModulesItem];
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
12
|
+
export const OrganizationDtoEnabledModulesItem = {
|
|
13
|
+
FEEDBACK: 'FEEDBACK',
|
|
14
|
+
HELP_CENTER: 'HELP_CENTER',
|
|
15
|
+
SUPPORT: 'SUPPORT',
|
|
16
|
+
CHANGELOG: 'CHANGELOG',
|
|
17
|
+
} as const;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @nullable
|
|
10
|
+
*/
|
|
11
|
+
export type OrganizationDtoRole =
|
|
12
|
+
| (typeof OrganizationDtoRole)[keyof typeof OrganizationDtoRole]
|
|
13
|
+
| null;
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
16
|
+
export const OrganizationDtoRole = {
|
|
17
|
+
Admin: "Admin",
|
|
18
|
+
Manager: "Manager",
|
|
19
|
+
User: "User",
|
|
20
|
+
} as const;
|
|
21
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The theme of the organization
|
|
10
|
+
*/
|
|
11
|
+
export type OrganizationDtoTheme =
|
|
12
|
+
(typeof OrganizationDtoTheme)[keyof typeof OrganizationDtoTheme];
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
15
|
+
export const OrganizationDtoTheme = {
|
|
16
|
+
Light: 'Light',
|
|
17
|
+
Dark: 'Dark',
|
|
18
|
+
} as const;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface OrganizationFeaturesDto {
|
|
9
|
+
maxSeats: number;
|
|
10
|
+
roleBeasedPermissions: boolean;
|
|
11
|
+
aiAssistant: boolean;
|
|
12
|
+
helpCenterCustomDomain: boolean;
|
|
13
|
+
changelogCustomDomain: boolean;
|
|
14
|
+
removeWorkWondersBranding: boolean;
|
|
15
|
+
widgets: boolean;
|
|
16
|
+
customChangelogCategories: boolean;
|
|
17
|
+
customFeedbackPostCategories: boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
import type { OrganizationFeedbackPostConfigDtoCopywriting } from './organizationFeedbackPostConfigDtoCopywriting';
|
|
8
|
+
|
|
9
|
+
export interface OrganizationFeedbackPostConfigDto {
|
|
10
|
+
copywriting: OrganizationFeedbackPostConfigDtoCopywriting;
|
|
11
|
+
allowDownvoting: boolean;
|
|
12
|
+
hideVoteCountUntilVote: boolean;
|
|
13
|
+
allowAnonymousVoting: boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
import type { OrganizationFeedbackPostCopywritingDto } from './organizationFeedbackPostCopywritingDto';
|
|
8
|
+
|
|
9
|
+
export type OrganizationFeedbackPostConfigDtoCopywriting = {
|
|
10
|
+
[key: string]: OrganizationFeedbackPostCopywritingDto;
|
|
11
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.11.2 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Work Wonders API
|
|
5
|
+
* OpenAPI spec version: 1.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface OrganizationFeedbackPostCopywritingDto {
|
|
9
|
+
title: string;
|
|
10
|
+
buttonText: string;
|
|
11
|
+
message: string;
|
|
12
|
+
widgetButtonText: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import ky from "ky";
|
|
2
|
+
import { type OrganizationDto } from "./types/organizationDto";
|
|
3
|
+
import { ChangelogSummaryDto } from "./types/changelogSummaryDto";
|
|
4
|
+
|
|
5
|
+
interface InitArgs {
|
|
6
|
+
organization: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
locale?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class WorkWondersSdk {
|
|
12
|
+
private ky = ky.create({
|
|
13
|
+
prefixUrl: import.meta.env.VITE_WORKWONDERS_API_URL,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
private $feedbackContainer: HTMLDivElement | null = null;
|
|
17
|
+
private $changelogContainer: HTMLDivElement | null = null;
|
|
18
|
+
private $changelogIframe: HTMLIFrameElement | null = null;
|
|
19
|
+
private $changelogMiniContainer: HTMLDivElement | null = null;
|
|
20
|
+
private $feedbackButton: HTMLButtonElement | null = null;
|
|
21
|
+
|
|
22
|
+
private widgetBaseUrl = "";
|
|
23
|
+
private args: InitArgs | null = null;
|
|
24
|
+
private organizationData: OrganizationDto | null = null;
|
|
25
|
+
|
|
26
|
+
private contextBasedChangelogs: ChangelogSummaryDto[] = [];
|
|
27
|
+
|
|
28
|
+
init = async (args: InitArgs) => {
|
|
29
|
+
this.args = args;
|
|
30
|
+
|
|
31
|
+
console.log(this.contextBasedChangelogs);
|
|
32
|
+
|
|
33
|
+
if (this.$changelogContainer) {
|
|
34
|
+
this.$changelogContainer.remove();
|
|
35
|
+
this.$changelogContainer = null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (this.$feedbackContainer) {
|
|
39
|
+
this.$feedbackContainer.remove();
|
|
40
|
+
this.$feedbackContainer = null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (this.$changelogMiniContainer) {
|
|
44
|
+
this.$changelogMiniContainer.remove();
|
|
45
|
+
this.$changelogMiniContainer = null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (this.$feedbackButton) {
|
|
49
|
+
this.$feedbackButton.remove();
|
|
50
|
+
this.$feedbackButton = null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!args.organization) {
|
|
54
|
+
console.error("Cannot init Work Wonders SDK. Organization is required.");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const organizationData = await this.ky
|
|
59
|
+
.get<OrganizationDto>(`organizations/${args.organization}`)
|
|
60
|
+
.then((res) => res.json());
|
|
61
|
+
|
|
62
|
+
if (organizationData.accessLevel === "Private" && !args.token) {
|
|
63
|
+
console.error(
|
|
64
|
+
"Cannot init Work Wonders SDK. This organization is private, a token is required."
|
|
65
|
+
);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!organizationData.features.widgets) {
|
|
70
|
+
console.error(
|
|
71
|
+
"Cannot init Work Wonders SDK. This organization does not have widgets feature enabled."
|
|
72
|
+
);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.organizationData = organizationData;
|
|
77
|
+
|
|
78
|
+
const language =
|
|
79
|
+
organizationData.languages.find((lang) => lang === args.locale) ??
|
|
80
|
+
organizationData.defaultLanguage;
|
|
81
|
+
|
|
82
|
+
args.locale = language;
|
|
83
|
+
|
|
84
|
+
const workwondersUrl = new URL(import.meta.env.VITE_WORKWONDERS_URL);
|
|
85
|
+
|
|
86
|
+
this.widgetBaseUrl = `https://${args.organization}.${workwondersUrl.host}/widget/`;
|
|
87
|
+
|
|
88
|
+
console.log("Work Wonders SDK initialized");
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
initFeedbackWidget = () => {
|
|
92
|
+
if (this.$feedbackContainer) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const args = this.args;
|
|
97
|
+
const organizationData = this.organizationData;
|
|
98
|
+
|
|
99
|
+
if (!args) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!organizationData) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!organizationData.enabledModules.includes("FEEDBACK")) {
|
|
108
|
+
console.warn("Feedback module is not enabled for this organization.");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const $feedbackContainer = document.createElement("div");
|
|
113
|
+
this.$feedbackContainer = $feedbackContainer;
|
|
114
|
+
|
|
115
|
+
$feedbackContainer.id = "workwonders-feedback-container";
|
|
116
|
+
$feedbackContainer.classList.add("workwonders-widget-container");
|
|
117
|
+
$feedbackContainer.classList.add("workwonders-widget-container--hidden");
|
|
118
|
+
|
|
119
|
+
const $feedbackIframe = document.createElement("iframe");
|
|
120
|
+
$feedbackIframe.id = "workwonders-feedback-iframe";
|
|
121
|
+
$feedbackIframe.classList.add("workwonders-widget-iframe");
|
|
122
|
+
$feedbackIframe.classList.add("workwonders-feedback-iframe");
|
|
123
|
+
|
|
124
|
+
const widgetUrl = new URL("feedback", `${this.widgetBaseUrl}`);
|
|
125
|
+
widgetUrl.searchParams.append("jwt", args.token || "");
|
|
126
|
+
widgetUrl.searchParams.append("lang", args.locale || "");
|
|
127
|
+
$feedbackIframe.src = widgetUrl.toString();
|
|
128
|
+
|
|
129
|
+
$feedbackContainer.onclick = () => {
|
|
130
|
+
this.closeFeedbackWidget();
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
$feedbackContainer.appendChild($feedbackIframe);
|
|
134
|
+
|
|
135
|
+
document.body.appendChild($feedbackContainer);
|
|
136
|
+
|
|
137
|
+
this.initFeedbackButton();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
private initFeedbackButton() {
|
|
141
|
+
if (this.$feedbackButton) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const args = this.args;
|
|
146
|
+
const organizationData = this.organizationData;
|
|
147
|
+
|
|
148
|
+
if (!args?.locale || !organizationData) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const $feedbackButton = document.createElement("button");
|
|
153
|
+
this.$feedbackButton = $feedbackButton;
|
|
154
|
+
|
|
155
|
+
const buttonText =
|
|
156
|
+
organizationData.feedbackPostConfig.copywriting[args.locale]
|
|
157
|
+
?.widgetButtonText ??
|
|
158
|
+
organizationData.feedbackPostConfig.copywriting[
|
|
159
|
+
organizationData.defaultLanguage
|
|
160
|
+
].widgetButtonText ??
|
|
161
|
+
"Feedback";
|
|
162
|
+
|
|
163
|
+
$feedbackButton.id = "workwonders-feedback-button";
|
|
164
|
+
$feedbackButton.textContent = buttonText;
|
|
165
|
+
$feedbackButton.classList.add("workwonders-feedback-button");
|
|
166
|
+
$feedbackButton.style.backgroundColor = organizationData.primaryColor;
|
|
167
|
+
|
|
168
|
+
$feedbackButton.onclick = () => {
|
|
169
|
+
this.openFeedbackWidget();
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
document.body.appendChild($feedbackButton);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
initChangelogWidget = async () => {
|
|
176
|
+
if (this.$changelogContainer) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const args = this.args;
|
|
181
|
+
const organizationData = this.organizationData;
|
|
182
|
+
|
|
183
|
+
if (!args?.locale || !organizationData) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!organizationData.enabledModules.includes("CHANGELOG")) {
|
|
188
|
+
console.warn("Changelog module is not enabled for this organization.");
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const $changelogContainer = document.createElement("div");
|
|
193
|
+
this.$changelogContainer = $changelogContainer;
|
|
194
|
+
|
|
195
|
+
const existingsChangelogs = await this.ky
|
|
196
|
+
.get<ChangelogSummaryDto[]>(
|
|
197
|
+
`organizations/${args.organization}/changelogs/summary?language=${args.locale}`
|
|
198
|
+
)
|
|
199
|
+
.then((res) => res.json())
|
|
200
|
+
.then((changelogs) =>
|
|
201
|
+
changelogs.sort(
|
|
202
|
+
(a: ChangelogSummaryDto, b: ChangelogSummaryDto) =>
|
|
203
|
+
new Date(b.publishedAt ?? 0).getTime() -
|
|
204
|
+
new Date(a.publishedAt ?? 0).getTime()
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const regularChangelogs = existingsChangelogs.filter(
|
|
209
|
+
(changelog: ChangelogSummaryDto) => changelog.showMode === "Regular"
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
this.contextBasedChangelogs = existingsChangelogs.filter(
|
|
213
|
+
(changelog: ChangelogSummaryDto) => changelog.showMode === "ContextBased"
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
$changelogContainer.id = "workwonders-changelog-container";
|
|
217
|
+
$changelogContainer.classList.add(
|
|
218
|
+
"workwonders-widget-container",
|
|
219
|
+
"workwonders-widget-container--hidden"
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const $changelogIframe = document.createElement("iframe");
|
|
223
|
+
$changelogIframe.id = "workwonders-changelog-iframe";
|
|
224
|
+
$changelogIframe.classList.add(
|
|
225
|
+
"workwonders-widget-iframe",
|
|
226
|
+
"workwonders-changelog-iframe"
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const seenChangelogs = localStorage.getItem(
|
|
230
|
+
`workwonders-seen-changelogs-${args.organization}`
|
|
231
|
+
);
|
|
232
|
+
const seenChangelogsArray = seenChangelogs
|
|
233
|
+
? JSON.parse(seenChangelogs)
|
|
234
|
+
: [];
|
|
235
|
+
|
|
236
|
+
const unseenChangelogs = regularChangelogs.filter(
|
|
237
|
+
(changelog: { id: number }) => !seenChangelogsArray.includes(changelog.id)
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const shouldShowChangelogOnStart =
|
|
241
|
+
unseenChangelogs.length > 0 &&
|
|
242
|
+
(seenChangelogsArray.length > 0 ||
|
|
243
|
+
organizationData.changelogConfig.showLatestChangelogOnFirstVisit);
|
|
244
|
+
|
|
245
|
+
if (shouldShowChangelogOnStart) {
|
|
246
|
+
const changelogIdsToShow =
|
|
247
|
+
seenChangelogsArray.length === 0
|
|
248
|
+
? [unseenChangelogs[0].id]
|
|
249
|
+
: unseenChangelogs.map((c: { id: number }) => c.id);
|
|
250
|
+
|
|
251
|
+
this.showChangelogs(changelogIdsToShow, args.locale);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
$changelogContainer.onclick = () => {
|
|
255
|
+
this.closeChangelogWidget();
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
document.body.appendChild($changelogContainer);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
showChangelogs = (changelogIdsToShow: number[], language: string) => {
|
|
262
|
+
const widgetUrl = new URL("changelog", `${this.widgetBaseUrl}`);
|
|
263
|
+
widgetUrl.searchParams.append("jwt", this.args?.token || "");
|
|
264
|
+
widgetUrl.searchParams.append("lang", language);
|
|
265
|
+
widgetUrl.searchParams.append("changelogIds", changelogIdsToShow.join(","));
|
|
266
|
+
|
|
267
|
+
const $changelogIframe = this.$changelogIframe;
|
|
268
|
+
const $changelogContainer = this.$changelogContainer;
|
|
269
|
+
|
|
270
|
+
if (!$changelogIframe || !$changelogContainer) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
$changelogIframe.src = widgetUrl.toString();
|
|
275
|
+
|
|
276
|
+
$changelogContainer.appendChild($changelogIframe);
|
|
277
|
+
|
|
278
|
+
$changelogIframe.onload = () => {
|
|
279
|
+
const currentSeenChangelogs = localStorage.getItem(
|
|
280
|
+
`workwonders-seen-changelogs-${this.args?.organization}`
|
|
281
|
+
);
|
|
282
|
+
const currentSeenChangelogsArray = currentSeenChangelogs
|
|
283
|
+
? JSON.parse(currentSeenChangelogs)
|
|
284
|
+
: [];
|
|
285
|
+
|
|
286
|
+
const newSeenChangelogs = [
|
|
287
|
+
...currentSeenChangelogsArray,
|
|
288
|
+
...changelogIdsToShow,
|
|
289
|
+
];
|
|
290
|
+
|
|
291
|
+
localStorage.setItem(
|
|
292
|
+
`workwonders-seen-changelogs-${this.args?.organization}`,
|
|
293
|
+
JSON.stringify(newSeenChangelogs)
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
$changelogContainer.classList.remove(
|
|
297
|
+
"workwonders-widget-container--hidden"
|
|
298
|
+
);
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
initChangelogWidgetMini = () => {
|
|
303
|
+
if (this.$changelogMiniContainer) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const args = this.args;
|
|
308
|
+
const organizationData = this.organizationData;
|
|
309
|
+
|
|
310
|
+
if (!args) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (!organizationData) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (!organizationData.enabledModules.includes("CHANGELOG")) {
|
|
319
|
+
console.warn("Changelog module is not enabled for this organization.");
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const $changelogMiniContainer = document.createElement("div");
|
|
324
|
+
this.$changelogMiniContainer = $changelogMiniContainer;
|
|
325
|
+
|
|
326
|
+
$changelogMiniContainer.id = "workwonders-changelog-mini-container";
|
|
327
|
+
$changelogMiniContainer.classList.add("workwonders-widget-container");
|
|
328
|
+
$changelogMiniContainer.classList.add(
|
|
329
|
+
"workwonders-changelog-mini-container"
|
|
330
|
+
);
|
|
331
|
+
$changelogMiniContainer.classList.add(
|
|
332
|
+
"workwonders-widget-container--hidden"
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
const $changelogMiniIframe = document.createElement("iframe");
|
|
336
|
+
$changelogMiniIframe.id = "workwonders-changelog-mini-iframe";
|
|
337
|
+
$changelogMiniIframe.classList.add("workwonders-widget-iframe");
|
|
338
|
+
$changelogMiniIframe.classList.add("workwonders-changelog-mini-iframe");
|
|
339
|
+
|
|
340
|
+
const widgetUrl = new URL("changelog/mini", `${this.widgetBaseUrl}`);
|
|
341
|
+
widgetUrl.searchParams.append("jwt", args.token || "");
|
|
342
|
+
widgetUrl.searchParams.append("lang", args.locale || "");
|
|
343
|
+
|
|
344
|
+
$changelogMiniIframe.src = widgetUrl.toString();
|
|
345
|
+
|
|
346
|
+
$changelogMiniContainer.appendChild($changelogMiniIframe);
|
|
347
|
+
|
|
348
|
+
$changelogMiniContainer.onclick = () => {
|
|
349
|
+
this.closeChangelogMiniWidget();
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
document.body.appendChild($changelogMiniContainer);
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
openFeedbackWidget = () => {
|
|
356
|
+
if (this.$feedbackContainer) {
|
|
357
|
+
this.$feedbackContainer.classList.remove(
|
|
358
|
+
"workwonders-widget-container--hidden"
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
openChangelogWidget = (id?: string) => {
|
|
364
|
+
if (this.$changelogContainer) {
|
|
365
|
+
if (id) {
|
|
366
|
+
const $iframe = document.getElementById(
|
|
367
|
+
"workwonders-changelog-iframe"
|
|
368
|
+
) as HTMLIFrameElement;
|
|
369
|
+
|
|
370
|
+
const widgetUrl = new URL("changelog", `${this.widgetBaseUrl}`);
|
|
371
|
+
widgetUrl.searchParams.append("jwt", this.args?.token || "");
|
|
372
|
+
widgetUrl.searchParams.append("lang", this.args?.locale || "");
|
|
373
|
+
widgetUrl.searchParams.append("changelogIds", id);
|
|
374
|
+
$iframe.src = widgetUrl.toString();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
this.$changelogContainer.classList.remove(
|
|
378
|
+
"workwonders-widget-container--hidden"
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
openChangelogMiniWidget = () => {
|
|
384
|
+
if (this.$changelogMiniContainer) {
|
|
385
|
+
console.log("Opening changelog mini");
|
|
386
|
+
this.$changelogMiniContainer.classList.remove(
|
|
387
|
+
"workwonders-widget-container--hidden"
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
closeChangelogWidget = () => {
|
|
393
|
+
if (this.$changelogContainer) {
|
|
394
|
+
this.$changelogContainer.classList.add(
|
|
395
|
+
"workwonders-widget-container--hidden"
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
closeFeedbackWidget = () => {
|
|
401
|
+
if (this.$feedbackContainer) {
|
|
402
|
+
this.$feedbackContainer.classList.add(
|
|
403
|
+
"workwonders-widget-container--hidden"
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
closeChangelogMiniWidget = () => {
|
|
409
|
+
if (this.$changelogMiniContainer) {
|
|
410
|
+
console.log("Closing changelog mini");
|
|
411
|
+
this.$changelogMiniContainer.classList.add(
|
|
412
|
+
"workwonders-widget-container--hidden"
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|