@capawesome/capacitor-intercom 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.
Files changed (73) hide show
  1. package/CapawesomeCapacitorIntercom.podspec +19 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +30 -0
  4. package/README.md +932 -0
  5. package/android/build.gradle +60 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/Intercom.java +441 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/IntercomHelper.java +38 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/IntercomPlugin.java +307 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/CustomException.java +20 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/CustomExceptions.java +23 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/events/UnreadConversationCountChangeEvent.java +22 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/HandlePushNotificationOptions.java +25 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/InitializeOptions.java +34 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/IsIntercomPushNotificationOptions.java +25 -0
  16. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/LogEventOptions.java +35 -0
  17. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/LoginUserOptions.java +33 -0
  18. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/PresentContentOptions.java +71 -0
  19. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/PresentMessageComposerOptions.java +20 -0
  20. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/PresentOptions.java +19 -0
  21. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SendPushTokenToIntercomOptions.java +24 -0
  22. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SetBottomPaddingOptions.java +22 -0
  23. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SetInAppMessagesVisibleOptions.java +22 -0
  24. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SetLauncherVisibleOptions.java +22 -0
  25. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SetUserHashOptions.java +24 -0
  26. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SetUserJwtOptions.java +24 -0
  27. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/UpdateUserOptions.java +108 -0
  28. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/results/GetUnreadConversationCountResult.java +22 -0
  29. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/results/IsIntercomPushNotificationResult.java +22 -0
  30. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/interfaces/Callback.java +5 -0
  31. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/interfaces/EmptyCallback.java +5 -0
  32. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/interfaces/NonEmptyResultCallback.java +7 -0
  33. package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/interfaces/Result.java +7 -0
  34. package/android/src/main/res/.gitkeep +0 -0
  35. package/dist/docs.json +1345 -0
  36. package/dist/esm/definitions.d.ts +549 -0
  37. package/dist/esm/definitions.js +27 -0
  38. package/dist/esm/definitions.js.map +1 -0
  39. package/dist/esm/index.d.ts +4 -0
  40. package/dist/esm/index.js +7 -0
  41. package/dist/esm/index.js.map +1 -0
  42. package/dist/esm/web.d.ts +34 -0
  43. package/dist/esm/web.js +175 -0
  44. package/dist/esm/web.js.map +1 -0
  45. package/dist/plugin.cjs.js +215 -0
  46. package/dist/plugin.cjs.js.map +1 -0
  47. package/dist/plugin.js +217 -0
  48. package/dist/plugin.js.map +1 -0
  49. package/ios/Plugin/Classes/Events/UnreadConversationCountChangeEvent.swift +16 -0
  50. package/ios/Plugin/Classes/Options/HandlePushNotificationOptions.swift +13 -0
  51. package/ios/Plugin/Classes/Options/InitializeOptions.swift +15 -0
  52. package/ios/Plugin/Classes/Options/IsIntercomPushNotificationOptions.swift +13 -0
  53. package/ios/Plugin/Classes/Options/LogEventOptions.swift +15 -0
  54. package/ios/Plugin/Classes/Options/LoginUserOptions.swift +17 -0
  55. package/ios/Plugin/Classes/Options/PresentContentOptions.swift +29 -0
  56. package/ios/Plugin/Classes/Options/PresentMessageComposerOptions.swift +10 -0
  57. package/ios/Plugin/Classes/Options/PresentOptions.swift +10 -0
  58. package/ios/Plugin/Classes/Options/SendPushTokenToIntercomOptions.swift +13 -0
  59. package/ios/Plugin/Classes/Options/SetBottomPaddingOptions.swift +13 -0
  60. package/ios/Plugin/Classes/Options/SetInAppMessagesVisibleOptions.swift +13 -0
  61. package/ios/Plugin/Classes/Options/SetLauncherVisibleOptions.swift +13 -0
  62. package/ios/Plugin/Classes/Options/SetUserHashOptions.swift +13 -0
  63. package/ios/Plugin/Classes/Options/SetUserJwtOptions.swift +13 -0
  64. package/ios/Plugin/Classes/Options/UpdateUserOptions.swift +38 -0
  65. package/ios/Plugin/Classes/Results/GetUnreadConversationCountResult.swift +16 -0
  66. package/ios/Plugin/Classes/Results/IsIntercomPushNotificationResult.swift +16 -0
  67. package/ios/Plugin/Enums/CustomError.swift +75 -0
  68. package/ios/Plugin/Info.plist +24 -0
  69. package/ios/Plugin/Intercom.swift +323 -0
  70. package/ios/Plugin/IntercomHelper.swift +17 -0
  71. package/ios/Plugin/IntercomPlugin.swift +261 -0
  72. package/ios/Plugin/Protocols/Result.swift +5 -0
  73. package/package.json +105 -0
@@ -0,0 +1,175 @@
1
+ import { CapacitorException, WebPlugin } from '@capacitor/core';
2
+ import IntercomMessenger, { hide, hideNotifications, onHide, onShow, onUnreadCountChange, shutdown, showArticle, showConversation, showNewMessage, showSpace, startSurvey, trackEvent, update, } from '@intercom/messenger-js-sdk';
3
+ import { ErrorCode } from './definitions';
4
+ export class IntercomWeb extends WebPlugin {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.initialized = false;
8
+ this.unreadConversationCount = 0;
9
+ }
10
+ async getUnreadConversationCount() {
11
+ return { count: this.unreadConversationCount };
12
+ }
13
+ async handlePushNotification() {
14
+ throw this.unimplemented('Not implemented on web.');
15
+ }
16
+ async hide() {
17
+ this.throwIfNotInitialized();
18
+ hide();
19
+ }
20
+ async initialize(options) {
21
+ this.appId = options.appId;
22
+ this.boot();
23
+ this.registerEventListeners();
24
+ this.initialized = true;
25
+ }
26
+ async isIntercomPushNotification() {
27
+ throw this.unimplemented('Not implemented on web.');
28
+ }
29
+ async logEvent(options) {
30
+ this.throwIfNotInitialized();
31
+ trackEvent(options.name, options.data);
32
+ }
33
+ async loginUnidentifiedUser() {
34
+ this.throwIfNotInitialized();
35
+ this.boot();
36
+ }
37
+ async loginUser(options) {
38
+ this.throwIfNotInitialized();
39
+ this.boot(options);
40
+ }
41
+ async logout() {
42
+ this.throwIfNotInitialized();
43
+ shutdown();
44
+ this.boot();
45
+ }
46
+ async present(options) {
47
+ var _a;
48
+ this.throwIfNotInitialized();
49
+ showSpace(IntercomWeb.mapSpace((_a = options === null || options === void 0 ? void 0 : options.space) !== null && _a !== void 0 ? _a : 'home'));
50
+ }
51
+ async presentContent(options) {
52
+ var _a, _b, _c;
53
+ this.throwIfNotInitialized();
54
+ switch (options.type) {
55
+ case 'article':
56
+ showArticle((_a = options.id) !== null && _a !== void 0 ? _a : '');
57
+ break;
58
+ case 'survey':
59
+ startSurvey((_b = options.id) !== null && _b !== void 0 ? _b : '');
60
+ break;
61
+ case 'conversation':
62
+ showConversation((_c = options.id) !== null && _c !== void 0 ? _c : '');
63
+ break;
64
+ default:
65
+ throw this.unavailable(IntercomWeb.errorNoWebEquivalent);
66
+ }
67
+ }
68
+ async presentMessageComposer(options) {
69
+ var _a;
70
+ this.throwIfNotInitialized();
71
+ showNewMessage((_a = options === null || options === void 0 ? void 0 : options.initialMessage) !== null && _a !== void 0 ? _a : '');
72
+ }
73
+ async sendPushTokenToIntercom() {
74
+ throw this.unimplemented('Not implemented on web.');
75
+ }
76
+ async setBottomPadding() {
77
+ throw this.unimplemented('Not implemented on web.');
78
+ }
79
+ async setInAppMessagesVisible(options) {
80
+ this.throwIfNotInitialized();
81
+ hideNotifications(!options.visible);
82
+ }
83
+ async setLauncherVisible(options) {
84
+ this.throwIfNotInitialized();
85
+ update({ hide_default_launcher: !options.visible });
86
+ }
87
+ async setUserHash(options) {
88
+ this.userHash = options.userHash;
89
+ }
90
+ async setUserJwt(options) {
91
+ this.userJwt = options.jwt;
92
+ }
93
+ async updateUser(options) {
94
+ this.throwIfNotInitialized();
95
+ const args = {};
96
+ if (options.userId !== undefined) {
97
+ args.user_id = options.userId;
98
+ }
99
+ if (options.email !== undefined) {
100
+ args.email = options.email;
101
+ }
102
+ if (options.name !== undefined) {
103
+ args.name = options.name;
104
+ }
105
+ if (options.phone !== undefined) {
106
+ args.phone = options.phone;
107
+ }
108
+ if (options.languageOverride !== undefined) {
109
+ args.language_override = options.languageOverride;
110
+ }
111
+ if (options.signedUpAt !== undefined) {
112
+ args.created_at = options.signedUpAt;
113
+ }
114
+ if (options.unsubscribedFromEmails !== undefined) {
115
+ args.unsubscribed_from_emails = options.unsubscribedFromEmails;
116
+ }
117
+ if (options.customAttributes !== undefined) {
118
+ Object.assign(args, options.customAttributes);
119
+ }
120
+ if (options.companies !== undefined) {
121
+ args.companies = options.companies.map(company => (Object.assign({ company_id: company.id, name: company.name, plan: company.plan, monthly_spend: company.monthlySpend, created_at: company.createdAt }, company.customAttributes)));
122
+ }
123
+ update(args);
124
+ }
125
+ boot(user) {
126
+ const settings = { app_id: this.appId };
127
+ if ((user === null || user === void 0 ? void 0 : user.userId) !== undefined) {
128
+ settings.user_id = user.userId;
129
+ }
130
+ if ((user === null || user === void 0 ? void 0 : user.email) !== undefined) {
131
+ settings.email = user.email;
132
+ }
133
+ if (this.userHash !== undefined) {
134
+ settings.user_hash = this.userHash;
135
+ }
136
+ if (this.userJwt !== undefined) {
137
+ settings.intercom_user_jwt = this.userJwt;
138
+ }
139
+ IntercomMessenger(settings);
140
+ }
141
+ static mapSpace(space) {
142
+ switch (space) {
143
+ case 'messages':
144
+ return 'messages';
145
+ case 'help-center':
146
+ return 'help';
147
+ case 'tickets':
148
+ return 'tickets';
149
+ default:
150
+ return 'home';
151
+ }
152
+ }
153
+ registerEventListeners() {
154
+ onUnreadCountChange((count) => {
155
+ this.unreadConversationCount = count;
156
+ this.notifyListeners('unreadConversationCountChange', { count });
157
+ });
158
+ onShow(() => {
159
+ this.notifyListeners('messengerShown', {});
160
+ });
161
+ onHide(() => {
162
+ this.notifyListeners('messengerHidden', {});
163
+ });
164
+ }
165
+ throwIfNotInitialized() {
166
+ if (!this.initialized) {
167
+ throw new CapacitorException(IntercomWeb.errorNotInitialized, undefined, {
168
+ code: ErrorCode.NotInitialized,
169
+ });
170
+ }
171
+ }
172
+ }
173
+ IntercomWeb.errorNotInitialized = 'Intercom is not initialized. Call initialize() first.';
174
+ IntercomWeb.errorNoWebEquivalent = 'This content type is not available on the web platform.';
175
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,iBAAiB,EAAE,EACxB,IAAI,EACJ,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,mBAAmB,EACnB,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,WAAW,EACX,UAAU,EACV,MAAM,GACP,MAAM,4BAA4B,CAAC;AAiBpC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CA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,CACgB","sourcesContent":["import { CapacitorException, WebPlugin } from '@capacitor/core';\nimport IntercomMessenger, {\n hide,\n hideNotifications,\n onHide,\n onShow,\n onUnreadCountChange,\n shutdown,\n showArticle,\n showConversation,\n showNewMessage,\n showSpace,\n startSurvey,\n trackEvent,\n update,\n} from '@intercom/messenger-js-sdk';\n\nimport type {\n GetUnreadConversationCountResult,\n InitializeOptions,\n IntercomPlugin,\n LogEventOptions,\n LoginUserOptions,\n PresentContentOptions,\n PresentMessageComposerOptions,\n PresentOptions,\n SetInAppMessagesVisibleOptions,\n SetLauncherVisibleOptions,\n SetUserHashOptions,\n SetUserJwtOptions,\n UpdateUserOptions,\n} from './definitions';\nimport { ErrorCode } from './definitions';\n\ntype BootSettings = Parameters<typeof IntercomMessenger>[0];\ntype UpdateArgs = Parameters<typeof update>[0];\n\nexport class IntercomWeb extends WebPlugin implements IntercomPlugin {\n private static readonly errorNotInitialized =\n 'Intercom is not initialized. Call initialize() first.';\n private static readonly errorNoWebEquivalent =\n 'This content type is not available on the web platform.';\n\n private appId?: string;\n private initialized = false;\n private unreadConversationCount = 0;\n private userHash?: string;\n private userJwt?: string;\n\n async getUnreadConversationCount(): Promise<GetUnreadConversationCountResult> {\n return { count: this.unreadConversationCount };\n }\n\n async handlePushNotification(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async hide(): Promise<void> {\n this.throwIfNotInitialized();\n hide();\n }\n\n async initialize(options: InitializeOptions): Promise<void> {\n this.appId = options.appId;\n this.boot();\n this.registerEventListeners();\n this.initialized = true;\n }\n\n async isIntercomPushNotification(): Promise<never> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async logEvent(options: LogEventOptions): Promise<void> {\n this.throwIfNotInitialized();\n trackEvent(options.name, options.data);\n }\n\n async loginUnidentifiedUser(): Promise<void> {\n this.throwIfNotInitialized();\n this.boot();\n }\n\n async loginUser(options: LoginUserOptions): Promise<void> {\n this.throwIfNotInitialized();\n this.boot(options);\n }\n\n async logout(): Promise<void> {\n this.throwIfNotInitialized();\n shutdown();\n this.boot();\n }\n\n async present(options?: PresentOptions): Promise<void> {\n this.throwIfNotInitialized();\n showSpace(IntercomWeb.mapSpace(options?.space ?? 'home'));\n }\n\n async presentContent(options: PresentContentOptions): Promise<void> {\n this.throwIfNotInitialized();\n switch (options.type) {\n case 'article':\n showArticle(options.id ?? '');\n break;\n case 'survey':\n startSurvey(options.id ?? '');\n break;\n case 'conversation':\n showConversation(options.id ?? '');\n break;\n default:\n throw this.unavailable(IntercomWeb.errorNoWebEquivalent);\n }\n }\n\n async presentMessageComposer(\n options?: PresentMessageComposerOptions,\n ): Promise<void> {\n this.throwIfNotInitialized();\n showNewMessage(options?.initialMessage ?? '');\n }\n\n async sendPushTokenToIntercom(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async setBottomPadding(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async setInAppMessagesVisible(\n options: SetInAppMessagesVisibleOptions,\n ): Promise<void> {\n this.throwIfNotInitialized();\n hideNotifications(!options.visible);\n }\n\n async setLauncherVisible(options: SetLauncherVisibleOptions): Promise<void> {\n this.throwIfNotInitialized();\n update({ hide_default_launcher: !options.visible } as UpdateArgs);\n }\n\n async setUserHash(options: SetUserHashOptions): Promise<void> {\n this.userHash = options.userHash;\n }\n\n async setUserJwt(options: SetUserJwtOptions): Promise<void> {\n this.userJwt = options.jwt;\n }\n\n async updateUser(options: UpdateUserOptions): Promise<void> {\n this.throwIfNotInitialized();\n const args: Record<string, unknown> = {};\n if (options.userId !== undefined) {\n args.user_id = options.userId;\n }\n if (options.email !== undefined) {\n args.email = options.email;\n }\n if (options.name !== undefined) {\n args.name = options.name;\n }\n if (options.phone !== undefined) {\n args.phone = options.phone;\n }\n if (options.languageOverride !== undefined) {\n args.language_override = options.languageOverride;\n }\n if (options.signedUpAt !== undefined) {\n args.created_at = options.signedUpAt;\n }\n if (options.unsubscribedFromEmails !== undefined) {\n args.unsubscribed_from_emails = options.unsubscribedFromEmails;\n }\n if (options.customAttributes !== undefined) {\n Object.assign(args, options.customAttributes);\n }\n if (options.companies !== undefined) {\n args.companies = options.companies.map(company => ({\n company_id: company.id,\n name: company.name,\n plan: company.plan,\n monthly_spend: company.monthlySpend,\n created_at: company.createdAt,\n ...company.customAttributes,\n }));\n }\n update(args as UpdateArgs);\n }\n\n private boot(user?: LoginUserOptions): void {\n const settings: Record<string, unknown> = { app_id: this.appId };\n if (user?.userId !== undefined) {\n settings.user_id = user.userId;\n }\n if (user?.email !== undefined) {\n settings.email = user.email;\n }\n if (this.userHash !== undefined) {\n settings.user_hash = this.userHash;\n }\n if (this.userJwt !== undefined) {\n settings.intercom_user_jwt = this.userJwt;\n }\n IntercomMessenger(settings as unknown as BootSettings);\n }\n\n private static mapSpace(space: string): string {\n switch (space) {\n case 'messages':\n return 'messages';\n case 'help-center':\n return 'help';\n case 'tickets':\n return 'tickets';\n default:\n return 'home';\n }\n }\n\n private registerEventListeners(): void {\n onUnreadCountChange((count: number) => {\n this.unreadConversationCount = count;\n this.notifyListeners('unreadConversationCountChange', { count });\n });\n onShow(() => {\n this.notifyListeners('messengerShown', {});\n });\n onHide(() => {\n this.notifyListeners('messengerHidden', {});\n });\n }\n\n private throwIfNotInitialized(): void {\n if (!this.initialized) {\n throw new CapacitorException(IntercomWeb.errorNotInitialized, undefined, {\n code: ErrorCode.NotInitialized,\n });\n }\n }\n}\n"]}
@@ -0,0 +1,215 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+ var IntercomMessenger = require('@intercom/messenger-js-sdk');
5
+
6
+ /**
7
+ * @since 0.1.0
8
+ */
9
+ exports.ErrorCode = void 0;
10
+ (function (ErrorCode) {
11
+ /**
12
+ * The login of the user failed.
13
+ *
14
+ * @since 0.1.0
15
+ */
16
+ ErrorCode["LoginFailed"] = "LOGIN_FAILED";
17
+ /**
18
+ * The plugin has not been initialized yet.
19
+ *
20
+ * Call `initialize(...)` before calling any other method.
21
+ *
22
+ * @since 0.1.0
23
+ */
24
+ ErrorCode["NotInitialized"] = "NOT_INITIALIZED";
25
+ /**
26
+ * The update of the user failed.
27
+ *
28
+ * @since 0.1.0
29
+ */
30
+ ErrorCode["UpdateFailed"] = "UPDATE_FAILED";
31
+ })(exports.ErrorCode || (exports.ErrorCode = {}));
32
+
33
+ const Intercom = core.registerPlugin('Intercom', {
34
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.IntercomWeb()),
35
+ });
36
+
37
+ class IntercomWeb extends core.WebPlugin {
38
+ constructor() {
39
+ super(...arguments);
40
+ this.initialized = false;
41
+ this.unreadConversationCount = 0;
42
+ }
43
+ async getUnreadConversationCount() {
44
+ return { count: this.unreadConversationCount };
45
+ }
46
+ async handlePushNotification() {
47
+ throw this.unimplemented('Not implemented on web.');
48
+ }
49
+ async hide() {
50
+ this.throwIfNotInitialized();
51
+ IntercomMessenger.hide();
52
+ }
53
+ async initialize(options) {
54
+ this.appId = options.appId;
55
+ this.boot();
56
+ this.registerEventListeners();
57
+ this.initialized = true;
58
+ }
59
+ async isIntercomPushNotification() {
60
+ throw this.unimplemented('Not implemented on web.');
61
+ }
62
+ async logEvent(options) {
63
+ this.throwIfNotInitialized();
64
+ IntercomMessenger.trackEvent(options.name, options.data);
65
+ }
66
+ async loginUnidentifiedUser() {
67
+ this.throwIfNotInitialized();
68
+ this.boot();
69
+ }
70
+ async loginUser(options) {
71
+ this.throwIfNotInitialized();
72
+ this.boot(options);
73
+ }
74
+ async logout() {
75
+ this.throwIfNotInitialized();
76
+ IntercomMessenger.shutdown();
77
+ this.boot();
78
+ }
79
+ async present(options) {
80
+ var _a;
81
+ this.throwIfNotInitialized();
82
+ IntercomMessenger.showSpace(IntercomWeb.mapSpace((_a = options === null || options === void 0 ? void 0 : options.space) !== null && _a !== void 0 ? _a : 'home'));
83
+ }
84
+ async presentContent(options) {
85
+ var _a, _b, _c;
86
+ this.throwIfNotInitialized();
87
+ switch (options.type) {
88
+ case 'article':
89
+ IntercomMessenger.showArticle((_a = options.id) !== null && _a !== void 0 ? _a : '');
90
+ break;
91
+ case 'survey':
92
+ IntercomMessenger.startSurvey((_b = options.id) !== null && _b !== void 0 ? _b : '');
93
+ break;
94
+ case 'conversation':
95
+ IntercomMessenger.showConversation((_c = options.id) !== null && _c !== void 0 ? _c : '');
96
+ break;
97
+ default:
98
+ throw this.unavailable(IntercomWeb.errorNoWebEquivalent);
99
+ }
100
+ }
101
+ async presentMessageComposer(options) {
102
+ var _a;
103
+ this.throwIfNotInitialized();
104
+ IntercomMessenger.showNewMessage((_a = options === null || options === void 0 ? void 0 : options.initialMessage) !== null && _a !== void 0 ? _a : '');
105
+ }
106
+ async sendPushTokenToIntercom() {
107
+ throw this.unimplemented('Not implemented on web.');
108
+ }
109
+ async setBottomPadding() {
110
+ throw this.unimplemented('Not implemented on web.');
111
+ }
112
+ async setInAppMessagesVisible(options) {
113
+ this.throwIfNotInitialized();
114
+ IntercomMessenger.hideNotifications(!options.visible);
115
+ }
116
+ async setLauncherVisible(options) {
117
+ this.throwIfNotInitialized();
118
+ IntercomMessenger.update({ hide_default_launcher: !options.visible });
119
+ }
120
+ async setUserHash(options) {
121
+ this.userHash = options.userHash;
122
+ }
123
+ async setUserJwt(options) {
124
+ this.userJwt = options.jwt;
125
+ }
126
+ async updateUser(options) {
127
+ this.throwIfNotInitialized();
128
+ const args = {};
129
+ if (options.userId !== undefined) {
130
+ args.user_id = options.userId;
131
+ }
132
+ if (options.email !== undefined) {
133
+ args.email = options.email;
134
+ }
135
+ if (options.name !== undefined) {
136
+ args.name = options.name;
137
+ }
138
+ if (options.phone !== undefined) {
139
+ args.phone = options.phone;
140
+ }
141
+ if (options.languageOverride !== undefined) {
142
+ args.language_override = options.languageOverride;
143
+ }
144
+ if (options.signedUpAt !== undefined) {
145
+ args.created_at = options.signedUpAt;
146
+ }
147
+ if (options.unsubscribedFromEmails !== undefined) {
148
+ args.unsubscribed_from_emails = options.unsubscribedFromEmails;
149
+ }
150
+ if (options.customAttributes !== undefined) {
151
+ Object.assign(args, options.customAttributes);
152
+ }
153
+ if (options.companies !== undefined) {
154
+ args.companies = options.companies.map(company => (Object.assign({ company_id: company.id, name: company.name, plan: company.plan, monthly_spend: company.monthlySpend, created_at: company.createdAt }, company.customAttributes)));
155
+ }
156
+ IntercomMessenger.update(args);
157
+ }
158
+ boot(user) {
159
+ const settings = { app_id: this.appId };
160
+ if ((user === null || user === void 0 ? void 0 : user.userId) !== undefined) {
161
+ settings.user_id = user.userId;
162
+ }
163
+ if ((user === null || user === void 0 ? void 0 : user.email) !== undefined) {
164
+ settings.email = user.email;
165
+ }
166
+ if (this.userHash !== undefined) {
167
+ settings.user_hash = this.userHash;
168
+ }
169
+ if (this.userJwt !== undefined) {
170
+ settings.intercom_user_jwt = this.userJwt;
171
+ }
172
+ IntercomMessenger(settings);
173
+ }
174
+ static mapSpace(space) {
175
+ switch (space) {
176
+ case 'messages':
177
+ return 'messages';
178
+ case 'help-center':
179
+ return 'help';
180
+ case 'tickets':
181
+ return 'tickets';
182
+ default:
183
+ return 'home';
184
+ }
185
+ }
186
+ registerEventListeners() {
187
+ IntercomMessenger.onUnreadCountChange((count) => {
188
+ this.unreadConversationCount = count;
189
+ this.notifyListeners('unreadConversationCountChange', { count });
190
+ });
191
+ IntercomMessenger.onShow(() => {
192
+ this.notifyListeners('messengerShown', {});
193
+ });
194
+ IntercomMessenger.onHide(() => {
195
+ this.notifyListeners('messengerHidden', {});
196
+ });
197
+ }
198
+ throwIfNotInitialized() {
199
+ if (!this.initialized) {
200
+ throw new core.CapacitorException(IntercomWeb.errorNotInitialized, undefined, {
201
+ code: exports.ErrorCode.NotInitialized,
202
+ });
203
+ }
204
+ }
205
+ }
206
+ IntercomWeb.errorNotInitialized = 'Intercom is not initialized. Call initialize() first.';
207
+ IntercomWeb.errorNoWebEquivalent = 'This content type is not available on the web platform.';
208
+
209
+ var web = /*#__PURE__*/Object.freeze({
210
+ __proto__: null,
211
+ IntercomWeb: IntercomWeb
212
+ });
213
+
214
+ exports.Intercom = Intercom;
215
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The login of the user failed.\n *\n * @since 0.1.0\n */\n ErrorCode[\"LoginFailed\"] = \"LOGIN_FAILED\";\n /**\n * The plugin has not been initialized yet.\n *\n * Call `initialize(...)` before calling any other method.\n *\n * @since 0.1.0\n */\n ErrorCode[\"NotInitialized\"] = \"NOT_INITIALIZED\";\n /**\n * The update of the user failed.\n *\n * @since 0.1.0\n */\n ErrorCode[\"UpdateFailed\"] = \"UPDATE_FAILED\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Intercom = registerPlugin('Intercom', {\n web: () => import('./web').then(m => new m.IntercomWeb()),\n});\nexport * from './definitions';\nexport { Intercom };\n//# sourceMappingURL=index.js.map","import { CapacitorException, WebPlugin } from '@capacitor/core';\nimport IntercomMessenger, { hide, hideNotifications, onHide, onShow, onUnreadCountChange, shutdown, showArticle, showConversation, showNewMessage, showSpace, startSurvey, trackEvent, update, } from '@intercom/messenger-js-sdk';\nimport { ErrorCode } from './definitions';\nexport class IntercomWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.initialized = false;\n this.unreadConversationCount = 0;\n }\n async getUnreadConversationCount() {\n return { count: this.unreadConversationCount };\n }\n async handlePushNotification() {\n throw this.unimplemented('Not implemented on web.');\n }\n async hide() {\n this.throwIfNotInitialized();\n hide();\n }\n async initialize(options) {\n this.appId = options.appId;\n this.boot();\n this.registerEventListeners();\n this.initialized = true;\n }\n async isIntercomPushNotification() {\n throw this.unimplemented('Not implemented on web.');\n }\n async logEvent(options) {\n this.throwIfNotInitialized();\n trackEvent(options.name, options.data);\n }\n async loginUnidentifiedUser() {\n this.throwIfNotInitialized();\n this.boot();\n }\n async loginUser(options) {\n this.throwIfNotInitialized();\n this.boot(options);\n }\n async logout() {\n this.throwIfNotInitialized();\n shutdown();\n this.boot();\n }\n async present(options) {\n var _a;\n this.throwIfNotInitialized();\n showSpace(IntercomWeb.mapSpace((_a = options === null || options === void 0 ? void 0 : options.space) !== null && _a !== void 0 ? _a : 'home'));\n }\n async presentContent(options) {\n var _a, _b, _c;\n this.throwIfNotInitialized();\n switch (options.type) {\n case 'article':\n showArticle((_a = options.id) !== null && _a !== void 0 ? _a : '');\n break;\n case 'survey':\n startSurvey((_b = options.id) !== null && _b !== void 0 ? _b : '');\n break;\n case 'conversation':\n showConversation((_c = options.id) !== null && _c !== void 0 ? _c : '');\n break;\n default:\n throw this.unavailable(IntercomWeb.errorNoWebEquivalent);\n }\n }\n async presentMessageComposer(options) {\n var _a;\n this.throwIfNotInitialized();\n showNewMessage((_a = options === null || options === void 0 ? void 0 : options.initialMessage) !== null && _a !== void 0 ? _a : '');\n }\n async sendPushTokenToIntercom() {\n throw this.unimplemented('Not implemented on web.');\n }\n async setBottomPadding() {\n throw this.unimplemented('Not implemented on web.');\n }\n async setInAppMessagesVisible(options) {\n this.throwIfNotInitialized();\n hideNotifications(!options.visible);\n }\n async setLauncherVisible(options) {\n this.throwIfNotInitialized();\n update({ hide_default_launcher: !options.visible });\n }\n async setUserHash(options) {\n this.userHash = options.userHash;\n }\n async setUserJwt(options) {\n this.userJwt = options.jwt;\n }\n async updateUser(options) {\n this.throwIfNotInitialized();\n const args = {};\n if (options.userId !== undefined) {\n args.user_id = options.userId;\n }\n if (options.email !== undefined) {\n args.email = options.email;\n }\n if (options.name !== undefined) {\n args.name = options.name;\n }\n if (options.phone !== undefined) {\n args.phone = options.phone;\n }\n if (options.languageOverride !== undefined) {\n args.language_override = options.languageOverride;\n }\n if (options.signedUpAt !== undefined) {\n args.created_at = options.signedUpAt;\n }\n if (options.unsubscribedFromEmails !== undefined) {\n args.unsubscribed_from_emails = options.unsubscribedFromEmails;\n }\n if (options.customAttributes !== undefined) {\n Object.assign(args, options.customAttributes);\n }\n if (options.companies !== undefined) {\n args.companies = options.companies.map(company => (Object.assign({ company_id: company.id, name: company.name, plan: company.plan, monthly_spend: company.monthlySpend, created_at: company.createdAt }, company.customAttributes)));\n }\n update(args);\n }\n boot(user) {\n const settings = { app_id: this.appId };\n if ((user === null || user === void 0 ? void 0 : user.userId) !== undefined) {\n settings.user_id = user.userId;\n }\n if ((user === null || user === void 0 ? void 0 : user.email) !== undefined) {\n settings.email = user.email;\n }\n if (this.userHash !== undefined) {\n settings.user_hash = this.userHash;\n }\n if (this.userJwt !== undefined) {\n settings.intercom_user_jwt = this.userJwt;\n }\n IntercomMessenger(settings);\n }\n static mapSpace(space) {\n switch (space) {\n case 'messages':\n return 'messages';\n case 'help-center':\n return 'help';\n case 'tickets':\n return 'tickets';\n default:\n return 'home';\n }\n }\n registerEventListeners() {\n onUnreadCountChange((count) => {\n this.unreadConversationCount = count;\n this.notifyListeners('unreadConversationCountChange', { count });\n });\n onShow(() => {\n this.notifyListeners('messengerShown', {});\n });\n onHide(() => {\n this.notifyListeners('messengerHidden', {});\n });\n }\n throwIfNotInitialized() {\n if (!this.initialized) {\n throw new CapacitorException(IntercomWeb.errorNotInitialized, undefined, {\n code: ErrorCode.NotInitialized,\n });\n }\n }\n}\nIntercomWeb.errorNotInitialized = 'Intercom is not initialized. Call initialize() first.';\nIntercomWeb.errorNoWebEquivalent = 'This content type is not available on the web platform.';\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin","hide","trackEvent","shutdown","showSpace","showArticle","startSurvey","showConversation","showNewMessage","hideNotifications","update","onUnreadCountChange","onShow","onHide","CapacitorException"],"mappings":";;;;;AAAA;AACA;AACA;AACWA;AACX,CAAC,UAAU,SAAS,EAAE;AACtB;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,aAAa,CAAC,GAAG,cAAc;AAC7C;AACA;AACA;AACA;AAC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;AACd,QAAQ;AACR,IAAI;AACJ;AACA,WAAW,CAAC,mBAAmB,GAAG,uDAAuD;AACzF,WAAW,CAAC,oBAAoB,GAAG,yDAAyD;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,217 @@
1
+ var capacitorFacebookSignIn = (function (exports, core, IntercomMessenger) {
2
+ 'use strict';
3
+
4
+ /**
5
+ * @since 0.1.0
6
+ */
7
+ exports.ErrorCode = void 0;
8
+ (function (ErrorCode) {
9
+ /**
10
+ * The login of the user failed.
11
+ *
12
+ * @since 0.1.0
13
+ */
14
+ ErrorCode["LoginFailed"] = "LOGIN_FAILED";
15
+ /**
16
+ * The plugin has not been initialized yet.
17
+ *
18
+ * Call `initialize(...)` before calling any other method.
19
+ *
20
+ * @since 0.1.0
21
+ */
22
+ ErrorCode["NotInitialized"] = "NOT_INITIALIZED";
23
+ /**
24
+ * The update of the user failed.
25
+ *
26
+ * @since 0.1.0
27
+ */
28
+ ErrorCode["UpdateFailed"] = "UPDATE_FAILED";
29
+ })(exports.ErrorCode || (exports.ErrorCode = {}));
30
+
31
+ const Intercom = core.registerPlugin('Intercom', {
32
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.IntercomWeb()),
33
+ });
34
+
35
+ class IntercomWeb extends core.WebPlugin {
36
+ constructor() {
37
+ super(...arguments);
38
+ this.initialized = false;
39
+ this.unreadConversationCount = 0;
40
+ }
41
+ async getUnreadConversationCount() {
42
+ return { count: this.unreadConversationCount };
43
+ }
44
+ async handlePushNotification() {
45
+ throw this.unimplemented('Not implemented on web.');
46
+ }
47
+ async hide() {
48
+ this.throwIfNotInitialized();
49
+ IntercomMessenger.hide();
50
+ }
51
+ async initialize(options) {
52
+ this.appId = options.appId;
53
+ this.boot();
54
+ this.registerEventListeners();
55
+ this.initialized = true;
56
+ }
57
+ async isIntercomPushNotification() {
58
+ throw this.unimplemented('Not implemented on web.');
59
+ }
60
+ async logEvent(options) {
61
+ this.throwIfNotInitialized();
62
+ IntercomMessenger.trackEvent(options.name, options.data);
63
+ }
64
+ async loginUnidentifiedUser() {
65
+ this.throwIfNotInitialized();
66
+ this.boot();
67
+ }
68
+ async loginUser(options) {
69
+ this.throwIfNotInitialized();
70
+ this.boot(options);
71
+ }
72
+ async logout() {
73
+ this.throwIfNotInitialized();
74
+ IntercomMessenger.shutdown();
75
+ this.boot();
76
+ }
77
+ async present(options) {
78
+ var _a;
79
+ this.throwIfNotInitialized();
80
+ IntercomMessenger.showSpace(IntercomWeb.mapSpace((_a = options === null || options === void 0 ? void 0 : options.space) !== null && _a !== void 0 ? _a : 'home'));
81
+ }
82
+ async presentContent(options) {
83
+ var _a, _b, _c;
84
+ this.throwIfNotInitialized();
85
+ switch (options.type) {
86
+ case 'article':
87
+ IntercomMessenger.showArticle((_a = options.id) !== null && _a !== void 0 ? _a : '');
88
+ break;
89
+ case 'survey':
90
+ IntercomMessenger.startSurvey((_b = options.id) !== null && _b !== void 0 ? _b : '');
91
+ break;
92
+ case 'conversation':
93
+ IntercomMessenger.showConversation((_c = options.id) !== null && _c !== void 0 ? _c : '');
94
+ break;
95
+ default:
96
+ throw this.unavailable(IntercomWeb.errorNoWebEquivalent);
97
+ }
98
+ }
99
+ async presentMessageComposer(options) {
100
+ var _a;
101
+ this.throwIfNotInitialized();
102
+ IntercomMessenger.showNewMessage((_a = options === null || options === void 0 ? void 0 : options.initialMessage) !== null && _a !== void 0 ? _a : '');
103
+ }
104
+ async sendPushTokenToIntercom() {
105
+ throw this.unimplemented('Not implemented on web.');
106
+ }
107
+ async setBottomPadding() {
108
+ throw this.unimplemented('Not implemented on web.');
109
+ }
110
+ async setInAppMessagesVisible(options) {
111
+ this.throwIfNotInitialized();
112
+ IntercomMessenger.hideNotifications(!options.visible);
113
+ }
114
+ async setLauncherVisible(options) {
115
+ this.throwIfNotInitialized();
116
+ IntercomMessenger.update({ hide_default_launcher: !options.visible });
117
+ }
118
+ async setUserHash(options) {
119
+ this.userHash = options.userHash;
120
+ }
121
+ async setUserJwt(options) {
122
+ this.userJwt = options.jwt;
123
+ }
124
+ async updateUser(options) {
125
+ this.throwIfNotInitialized();
126
+ const args = {};
127
+ if (options.userId !== undefined) {
128
+ args.user_id = options.userId;
129
+ }
130
+ if (options.email !== undefined) {
131
+ args.email = options.email;
132
+ }
133
+ if (options.name !== undefined) {
134
+ args.name = options.name;
135
+ }
136
+ if (options.phone !== undefined) {
137
+ args.phone = options.phone;
138
+ }
139
+ if (options.languageOverride !== undefined) {
140
+ args.language_override = options.languageOverride;
141
+ }
142
+ if (options.signedUpAt !== undefined) {
143
+ args.created_at = options.signedUpAt;
144
+ }
145
+ if (options.unsubscribedFromEmails !== undefined) {
146
+ args.unsubscribed_from_emails = options.unsubscribedFromEmails;
147
+ }
148
+ if (options.customAttributes !== undefined) {
149
+ Object.assign(args, options.customAttributes);
150
+ }
151
+ if (options.companies !== undefined) {
152
+ args.companies = options.companies.map(company => (Object.assign({ company_id: company.id, name: company.name, plan: company.plan, monthly_spend: company.monthlySpend, created_at: company.createdAt }, company.customAttributes)));
153
+ }
154
+ IntercomMessenger.update(args);
155
+ }
156
+ boot(user) {
157
+ const settings = { app_id: this.appId };
158
+ if ((user === null || user === void 0 ? void 0 : user.userId) !== undefined) {
159
+ settings.user_id = user.userId;
160
+ }
161
+ if ((user === null || user === void 0 ? void 0 : user.email) !== undefined) {
162
+ settings.email = user.email;
163
+ }
164
+ if (this.userHash !== undefined) {
165
+ settings.user_hash = this.userHash;
166
+ }
167
+ if (this.userJwt !== undefined) {
168
+ settings.intercom_user_jwt = this.userJwt;
169
+ }
170
+ IntercomMessenger(settings);
171
+ }
172
+ static mapSpace(space) {
173
+ switch (space) {
174
+ case 'messages':
175
+ return 'messages';
176
+ case 'help-center':
177
+ return 'help';
178
+ case 'tickets':
179
+ return 'tickets';
180
+ default:
181
+ return 'home';
182
+ }
183
+ }
184
+ registerEventListeners() {
185
+ IntercomMessenger.onUnreadCountChange((count) => {
186
+ this.unreadConversationCount = count;
187
+ this.notifyListeners('unreadConversationCountChange', { count });
188
+ });
189
+ IntercomMessenger.onShow(() => {
190
+ this.notifyListeners('messengerShown', {});
191
+ });
192
+ IntercomMessenger.onHide(() => {
193
+ this.notifyListeners('messengerHidden', {});
194
+ });
195
+ }
196
+ throwIfNotInitialized() {
197
+ if (!this.initialized) {
198
+ throw new core.CapacitorException(IntercomWeb.errorNotInitialized, undefined, {
199
+ code: exports.ErrorCode.NotInitialized,
200
+ });
201
+ }
202
+ }
203
+ }
204
+ IntercomWeb.errorNotInitialized = 'Intercom is not initialized. Call initialize() first.';
205
+ IntercomWeb.errorNoWebEquivalent = 'This content type is not available on the web platform.';
206
+
207
+ var web = /*#__PURE__*/Object.freeze({
208
+ __proto__: null,
209
+ IntercomWeb: IntercomWeb
210
+ });
211
+
212
+ exports.Intercom = Intercom;
213
+
214
+ return exports;
215
+
216
+ })({}, capacitorExports, IntercomMessenger);
217
+ //# sourceMappingURL=plugin.js.map