@snugdesk/whatsapp-widget 0.2.1 → 0.2.2

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 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
@@ -56,14 +56,23 @@ function provideAppSyncConfig(config) {
56
56
  useValue: config,
57
57
  };
58
58
  }
59
+ const AMPLIFY_CONFIG = new InjectionToken('AMPLIFY_CONFIG');
60
+ function provideAmplifyConfig(config) {
61
+ return {
62
+ provide: AMPLIFY_CONFIG,
63
+ useValue: config,
64
+ };
65
+ }
59
66
  class AppSyncGraphqlService {
60
67
  authenticationService;
61
68
  configured = false;
62
69
  authMode = GRAPHQL_AUTH_MODE.AWS_LAMBDA;
63
70
  config;
64
- constructor(config, authenticationService) {
71
+ amplifyConfig;
72
+ constructor(config, amplifyConfig, authenticationService) {
65
73
  this.authenticationService = authenticationService;
66
74
  this.config = config ?? defaultAppSyncConfig;
75
+ this.amplifyConfig = amplifyConfig;
67
76
  // this.ensureConfigured();
68
77
  }
69
78
  async query(statement, variables) {
@@ -142,6 +151,12 @@ class AppSyncGraphqlService {
142
151
  if (this.configured) {
143
152
  return;
144
153
  }
154
+ if (this.amplifyConfig) {
155
+ Amplify.configure(this.amplifyConfig);
156
+ this.authMode = this.normalizeAuthMode(this.getAuthModeFromConfig(this.amplifyConfig)) ?? GRAPHQL_AUTH_MODE.API_KEY;
157
+ this.configured = true;
158
+ return;
159
+ }
145
160
  const hostConfig = this.getHostConfig();
146
161
  if (hostConfig.useHost) {
147
162
  this.authMode = this.normalizeAuthMode(hostConfig.authMode) ?? GRAPHQL_AUTH_MODE.API_KEY;
@@ -176,14 +191,8 @@ class AppSyncGraphqlService {
176
191
  const existing = Amplify.getConfig?.() ?? {};
177
192
  const existingEndpoint = existing?.API?.GraphQL?.endpoint ?? existing?.API?.GraphQL?.graphql_endpoint ?? existing?.aws_appsync_graphqlEndpoint;
178
193
  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
194
  return {
186
- useHost,
195
+ useHost: existingEndpoint === defaultAppSyncConfig.endpoint,
187
196
  authMode: existingAuthMode,
188
197
  };
189
198
  }
@@ -206,6 +215,9 @@ class AppSyncGraphqlService {
206
215
  return undefined;
207
216
  }
208
217
  }
218
+ getAuthModeFromConfig(config) {
219
+ return config?.API?.GraphQL?.defaultAuthMode ?? config?.aws_appsync_authenticationType;
220
+ }
209
221
  buildAuthHeaders() {
210
222
  const token = this.getToken();
211
223
  if (!token) {
@@ -222,7 +234,7 @@ class AppSyncGraphqlService {
222
234
  }
223
235
  return token;
224
236
  }
225
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppSyncGraphqlService, deps: [{ token: APPSYNC_GRAPHQL_CONFIG, optional: true }, { token: i1.SnugdeskAuthenticationService }], target: i0.ɵɵFactoryTarget.Injectable });
237
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppSyncGraphqlService, deps: [{ token: APPSYNC_GRAPHQL_CONFIG, optional: true }, { token: AMPLIFY_CONFIG, optional: true }, { token: i1.SnugdeskAuthenticationService }], target: i0.ɵɵFactoryTarget.Injectable });
226
238
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppSyncGraphqlService, providedIn: 'root' });
227
239
  }
228
240
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: AppSyncGraphqlService, decorators: [{
@@ -235,6 +247,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
235
247
  }, {
236
248
  type: Inject,
237
249
  args: [APPSYNC_GRAPHQL_CONFIG]
250
+ }] }, { type: undefined, decorators: [{
251
+ type: Optional
252
+ }, {
253
+ type: Inject,
254
+ args: [AMPLIFY_CONFIG]
238
255
  }] }, { type: i1.SnugdeskAuthenticationService }] });
239
256
 
240
257
  var ModelAttributeTypes;
@@ -6371,5 +6388,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
6371
6388
  * Generated bundle index. Do not edit.
6372
6389
  */
6373
6390
 
6374
- export { APPSYNC_GRAPHQL_CONFIG, AppSyncGraphqlService, CustomError, LocationInputComponent, PhoneInputComponent, WhatsAppContactCreateComponent, WhatsAppContactListComponent, WhatsAppConversationsComponent, WhatsAppMessageItemComponent, WhatsAppMessagesComponent, WhatsAppTemplatePreviewComponent, WhatsAppTemplatesComponent, WhatsAppTextFormatterPipe, WhatsAppWidgetComponent, WhatsAppWidgetModule, provideAppSyncConfig };
6391
+ export { AMPLIFY_CONFIG, APPSYNC_GRAPHQL_CONFIG, AppSyncGraphqlService, CustomError, LocationInputComponent, PhoneInputComponent, WhatsAppContactCreateComponent, WhatsAppContactListComponent, WhatsAppConversationsComponent, WhatsAppMessageItemComponent, WhatsAppMessagesComponent, WhatsAppTemplatePreviewComponent, WhatsAppTemplatesComponent, WhatsAppTextFormatterPipe, WhatsAppWidgetComponent, WhatsAppWidgetModule, provideAmplifyConfig, provideAppSyncConfig };
6375
6392
  //# sourceMappingURL=snugdesk-whatsapp-widget.mjs.map