@snugdesk/whatsapp-widget 0.2.1 → 0.2.3
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.
Potentially problematic release.
This version of @snugdesk/whatsapp-widget might be problematic. Click here for more details.
- package/README.md +12 -0
- package/fesm2022/snugdesk-whatsapp-widget.mjs +54 -55
- package/fesm2022/snugdesk-whatsapp-widget.mjs.map +1 -1
- package/index.d.ts +13 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -180,6 +180,18 @@ The widget can run in two modes without any extra setup from third parties:
|
|
|
180
180
|
- The widget honors the host AppSync auth mode when it reuses the host config (for example, `API_KEY` vs `AWS_LAMBDA`).
|
|
181
181
|
- Otherwise, the widget will **configure Amplify itself** using its default configuration (`AWS_LAMBDA`).
|
|
182
182
|
|
|
183
|
+
You can also pass your host Amplify config directly to the widget:
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
import { provideAmplifyConfig } from '@snugdesk/whatsapp-widget';
|
|
187
|
+
import { AmplifyConfig } from './app/app-config.model';
|
|
188
|
+
|
|
189
|
+
@NgModule({
|
|
190
|
+
providers: [provideAmplifyConfig(AmplifyConfig)]
|
|
191
|
+
})
|
|
192
|
+
export class AppModule {}
|
|
193
|
+
```
|
|
194
|
+
|
|
183
195
|
---
|
|
184
196
|
|
|
185
197
|
## 🎨 Assets & Styling
|
|
@@ -22,12 +22,12 @@ import * as i6$1 from '@angular/material/select';
|
|
|
22
22
|
import { MatSelectModule } from '@angular/material/select';
|
|
23
23
|
import * as i1 from '@snugdesk/core';
|
|
24
24
|
import { CustomValidators, CleanDeep, SnugdeskCoreModule, CustomPipesModule } from '@snugdesk/core';
|
|
25
|
-
import { API, Amplify } from 'aws-amplify';
|
|
26
|
-
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
27
25
|
import moment from 'moment-timezone';
|
|
28
26
|
import { lastValueFrom, BehaviorSubject } from 'rxjs';
|
|
29
27
|
import * as i1$1 from '@angular/common/http';
|
|
30
28
|
import { HttpHeaders } from '@angular/common/http';
|
|
29
|
+
import { API, Amplify } from 'aws-amplify';
|
|
30
|
+
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
31
31
|
import * as i3 from '@angular/material/snack-bar';
|
|
32
32
|
import { parsePhoneNumberFromString } from 'libphonenumber-js';
|
|
33
33
|
import * as i6$2 from 'ngx-avatars';
|
|
@@ -44,15 +44,36 @@ import { sort } from 'sort-nested-json';
|
|
|
44
44
|
import * as i16 from '@ctrl/ngx-emoji-mart';
|
|
45
45
|
import { PickerModule } from '@ctrl/ngx-emoji-mart';
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
var ModelAttributeTypes;
|
|
48
|
+
(function (ModelAttributeTypes) {
|
|
49
|
+
ModelAttributeTypes["binary"] = "binary";
|
|
50
|
+
ModelAttributeTypes["binarySet"] = "binarySet";
|
|
51
|
+
ModelAttributeTypes["bool"] = "bool";
|
|
52
|
+
ModelAttributeTypes["list"] = "list";
|
|
53
|
+
ModelAttributeTypes["map"] = "map";
|
|
54
|
+
ModelAttributeTypes["number"] = "number";
|
|
55
|
+
ModelAttributeTypes["numberSet"] = "numberSet";
|
|
56
|
+
ModelAttributeTypes["string"] = "string";
|
|
57
|
+
ModelAttributeTypes["stringSet"] = "stringSet";
|
|
58
|
+
ModelAttributeTypes["_null"] = "_null";
|
|
59
|
+
})(ModelAttributeTypes || (ModelAttributeTypes = {}));
|
|
60
|
+
var ModelSortDirection;
|
|
61
|
+
(function (ModelSortDirection) {
|
|
62
|
+
ModelSortDirection["ASC"] = "ASC";
|
|
63
|
+
ModelSortDirection["DESC"] = "DESC";
|
|
64
|
+
})(ModelSortDirection || (ModelSortDirection = {}));
|
|
65
|
+
|
|
66
|
+
const defaultAmplifyConfig = {
|
|
67
|
+
aws_project_region: 'ap-south-1',
|
|
68
|
+
aws_appsync_graphqlEndpoint: 'https://sgbnsklbvrh67mcvh3wqkzgyou.appsync-api.ap-south-1.amazonaws.com/graphql',
|
|
69
|
+
aws_appsync_region: 'ap-south-1',
|
|
70
|
+
aws_appsync_authenticationType: 'AWS_LAMBDA',
|
|
50
71
|
};
|
|
51
72
|
|
|
52
|
-
const
|
|
53
|
-
function
|
|
73
|
+
const AMPLIFY_CONFIG = new InjectionToken('AMPLIFY_CONFIG');
|
|
74
|
+
function provideAmplifyConfig(config) {
|
|
54
75
|
return {
|
|
55
|
-
provide:
|
|
76
|
+
provide: AMPLIFY_CONFIG,
|
|
56
77
|
useValue: config,
|
|
57
78
|
};
|
|
58
79
|
}
|
|
@@ -60,10 +81,10 @@ class AppSyncGraphqlService {
|
|
|
60
81
|
authenticationService;
|
|
61
82
|
configured = false;
|
|
62
83
|
authMode = GRAPHQL_AUTH_MODE.AWS_LAMBDA;
|
|
63
|
-
|
|
64
|
-
constructor(
|
|
84
|
+
amplifyConfig;
|
|
85
|
+
constructor(amplifyConfig, authenticationService) {
|
|
65
86
|
this.authenticationService = authenticationService;
|
|
66
|
-
this.
|
|
87
|
+
this.amplifyConfig = amplifyConfig;
|
|
67
88
|
// this.ensureConfigured();
|
|
68
89
|
}
|
|
69
90
|
async query(statement, variables) {
|
|
@@ -142,26 +163,26 @@ class AppSyncGraphqlService {
|
|
|
142
163
|
if (this.configured) {
|
|
143
164
|
return;
|
|
144
165
|
}
|
|
166
|
+
if (this.amplifyConfig) {
|
|
167
|
+
Amplify.configure(this.amplifyConfig);
|
|
168
|
+
this.authMode = this.normalizeAuthMode(this.getAuthModeFromConfig(this.amplifyConfig));
|
|
169
|
+
this.configured = true;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
145
172
|
const hostConfig = this.getHostConfig();
|
|
146
173
|
if (hostConfig.useHost) {
|
|
147
|
-
this.authMode = this.normalizeAuthMode(hostConfig.authMode)
|
|
174
|
+
this.authMode = this.normalizeAuthMode(hostConfig.authMode);
|
|
148
175
|
this.configured = true;
|
|
149
176
|
return;
|
|
150
177
|
}
|
|
151
|
-
if (!this.config?.endpoint || !this.config?.region) {
|
|
152
|
-
throw new Error('AppSync GraphQL configuration is missing.');
|
|
153
|
-
}
|
|
154
|
-
const { endpoint, region } = this.config;
|
|
155
178
|
Amplify.configure({
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
aws_appsync_region: region,
|
|
159
|
-
aws_appsync_authenticationType: GRAPHQL_AUTH_MODE.AWS_LAMBDA,
|
|
179
|
+
...defaultAmplifyConfig,
|
|
180
|
+
aws_appsync_authenticationType: this.normalizeAuthMode(defaultAmplifyConfig.aws_appsync_authenticationType),
|
|
160
181
|
API: {
|
|
161
182
|
GraphQL: {
|
|
162
|
-
endpoint,
|
|
163
|
-
region,
|
|
164
|
-
defaultAuthMode:
|
|
183
|
+
endpoint: defaultAmplifyConfig.aws_appsync_graphqlEndpoint,
|
|
184
|
+
region: defaultAmplifyConfig.aws_appsync_region,
|
|
185
|
+
defaultAuthMode: this.normalizeAuthMode(defaultAmplifyConfig.aws_appsync_authenticationType),
|
|
165
186
|
graphql_headers: async () => this.buildAuthHeaders(),
|
|
166
187
|
functionAuthProvider: async () => ({
|
|
167
188
|
token: this.getToken(),
|
|
@@ -169,21 +190,15 @@ class AppSyncGraphqlService {
|
|
|
169
190
|
},
|
|
170
191
|
},
|
|
171
192
|
});
|
|
172
|
-
this.authMode =
|
|
193
|
+
this.authMode = this.normalizeAuthMode(defaultAmplifyConfig.aws_appsync_authenticationType);
|
|
173
194
|
this.configured = true;
|
|
174
195
|
}
|
|
175
196
|
getHostConfig() {
|
|
176
197
|
const existing = Amplify.getConfig?.() ?? {};
|
|
177
198
|
const existingEndpoint = existing?.API?.GraphQL?.endpoint ?? existing?.API?.GraphQL?.graphql_endpoint ?? existing?.aws_appsync_graphqlEndpoint;
|
|
178
199
|
const existingAuthMode = existing?.API?.GraphQL?.defaultAuthMode ?? existing?.aws_appsync_authenticationType;
|
|
179
|
-
const useHost = existingEndpoint === defaultAppSyncConfig.endpoint;
|
|
180
|
-
console.debug('[WhatsAppWidget] Host Amplify config', {
|
|
181
|
-
existingEndpoint,
|
|
182
|
-
existingAuthMode,
|
|
183
|
-
useHost,
|
|
184
|
-
});
|
|
185
200
|
return {
|
|
186
|
-
useHost,
|
|
201
|
+
useHost: existingEndpoint === defaultAmplifyConfig.aws_appsync_graphqlEndpoint,
|
|
187
202
|
authMode: existingAuthMode,
|
|
188
203
|
};
|
|
189
204
|
}
|
|
@@ -206,6 +221,9 @@ class AppSyncGraphqlService {
|
|
|
206
221
|
return undefined;
|
|
207
222
|
}
|
|
208
223
|
}
|
|
224
|
+
getAuthModeFromConfig(config) {
|
|
225
|
+
return config?.API?.GraphQL?.defaultAuthMode ?? config?.aws_appsync_authenticationType;
|
|
226
|
+
}
|
|
209
227
|
buildAuthHeaders() {
|
|
210
228
|
const token = this.getToken();
|
|
211
229
|
if (!token) {
|
|
@@ -222,7 +240,7 @@ class AppSyncGraphqlService {
|
|
|
222
240
|
}
|
|
223
241
|
return token;
|
|
224
242
|
}
|
|
225
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppSyncGraphqlService, deps: [{ token:
|
|
243
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppSyncGraphqlService, deps: [{ token: AMPLIFY_CONFIG, optional: true }, { token: i1.SnugdeskAuthenticationService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
226
244
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppSyncGraphqlService, providedIn: 'root' });
|
|
227
245
|
}
|
|
228
246
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppSyncGraphqlService, decorators: [{
|
|
@@ -234,28 +252,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
|
|
|
234
252
|
type: Optional
|
|
235
253
|
}, {
|
|
236
254
|
type: Inject,
|
|
237
|
-
args: [
|
|
255
|
+
args: [AMPLIFY_CONFIG]
|
|
238
256
|
}] }, { type: i1.SnugdeskAuthenticationService }] });
|
|
239
257
|
|
|
240
|
-
var ModelAttributeTypes;
|
|
241
|
-
(function (ModelAttributeTypes) {
|
|
242
|
-
ModelAttributeTypes["binary"] = "binary";
|
|
243
|
-
ModelAttributeTypes["binarySet"] = "binarySet";
|
|
244
|
-
ModelAttributeTypes["bool"] = "bool";
|
|
245
|
-
ModelAttributeTypes["list"] = "list";
|
|
246
|
-
ModelAttributeTypes["map"] = "map";
|
|
247
|
-
ModelAttributeTypes["number"] = "number";
|
|
248
|
-
ModelAttributeTypes["numberSet"] = "numberSet";
|
|
249
|
-
ModelAttributeTypes["string"] = "string";
|
|
250
|
-
ModelAttributeTypes["stringSet"] = "stringSet";
|
|
251
|
-
ModelAttributeTypes["_null"] = "_null";
|
|
252
|
-
})(ModelAttributeTypes || (ModelAttributeTypes = {}));
|
|
253
|
-
var ModelSortDirection;
|
|
254
|
-
(function (ModelSortDirection) {
|
|
255
|
-
ModelSortDirection["ASC"] = "ASC";
|
|
256
|
-
ModelSortDirection["DESC"] = "DESC";
|
|
257
|
-
})(ModelSortDirection || (ModelSortDirection = {}));
|
|
258
|
-
|
|
259
258
|
const ENTITY_SELECTION = /* GraphQL */ `
|
|
260
259
|
id
|
|
261
260
|
externalId
|
|
@@ -6298,7 +6297,7 @@ class WhatsAppWidgetModule {
|
|
|
6298
6297
|
InfiniteScrollDirective,
|
|
6299
6298
|
NgxSkeletonLoaderModule,
|
|
6300
6299
|
PickerModule], exports: [WhatsAppWidgetComponent, WhatsAppTextFormatterPipe] });
|
|
6301
|
-
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: WhatsAppWidgetModule,
|
|
6300
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: WhatsAppWidgetModule, imports: [CommonModule,
|
|
6302
6301
|
FormsModule,
|
|
6303
6302
|
ReactiveFormsModule,
|
|
6304
6303
|
MatNativeDateModule,
|
|
@@ -6359,7 +6358,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
|
|
|
6359
6358
|
PickerModule,
|
|
6360
6359
|
],
|
|
6361
6360
|
exports: [WhatsAppWidgetComponent, WhatsAppTextFormatterPipe],
|
|
6362
|
-
providers: [
|
|
6361
|
+
// providers: [provideAmplifyConfig(defaultAmplifyConfig)],
|
|
6363
6362
|
}]
|
|
6364
6363
|
}] });
|
|
6365
6364
|
|
|
@@ -6371,5 +6370,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
|
|
|
6371
6370
|
* Generated bundle index. Do not edit.
|
|
6372
6371
|
*/
|
|
6373
6372
|
|
|
6374
|
-
export {
|
|
6373
|
+
export { AMPLIFY_CONFIG, AppSyncGraphqlService, CustomError, LocationInputComponent, PhoneInputComponent, WhatsAppContactCreateComponent, WhatsAppContactListComponent, WhatsAppConversationsComponent, WhatsAppMessageItemComponent, WhatsAppMessagesComponent, WhatsAppTemplatePreviewComponent, WhatsAppTemplatesComponent, WhatsAppTextFormatterPipe, WhatsAppWidgetComponent, WhatsAppWidgetModule, provideAmplifyConfig };
|
|
6375
6374
|
//# sourceMappingURL=snugdesk-whatsapp-widget.mjs.map
|