@snugdesk/whatsapp-widget 0.1.7 → 0.1.8

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
@@ -25,7 +25,13 @@ npm install @snugdesk/core
25
25
  npm install @snugdesk/whatsapp-widget
26
26
  ```
27
27
 
28
- The widget bundle brings its own runtime dependencies (`aws-amplify`, `@aws-amplify/api-graphql`, `@aws-sdk/client-s3`, `@ctrl/ngx-emoji-mart`, `ngx-avatars`, `ngx-infinite-scroll`, `ngx-skeleton-loader`, `moment-timezone`, `libphonenumber-js`, `sort-nested-json`, `uuid`, …). No extra manual installs are needed unless you want to pin specific versions in your workspace.
28
+ The widget expects the host app to provide Amplify packages (peer dependencies). If your app does not already use Amplify, install them explicitly:
29
+
30
+ ```bash
31
+ npm install aws-amplify @aws-amplify/api-graphql
32
+ ```
33
+
34
+ Other runtime dependencies are bundled (`@aws-sdk/client-s3`, `@ctrl/ngx-emoji-mart`, `ngx-avatars`, `ngx-infinite-scroll`, `ngx-skeleton-loader`, `moment-timezone`, `libphonenumber-js`, `sort-nested-json`, `uuid`, …).
29
35
 
30
36
  ---
31
37
 
@@ -166,6 +172,15 @@ Ensure you render the widget only after you have a fresh token to avoid the comp
166
172
 
167
173
  ---
168
174
 
175
+ ## 🧩 Amplify Configuration Behavior
176
+
177
+ The widget can run in two modes without any extra setup from third parties:
178
+
179
+ - If the host already configured Amplify and its AppSync endpoint matches the widget default (`defaultAppSyncConfig.endpoint`), the widget will **reuse the host config** and **skip** `Amplify.configure`.
180
+ - Otherwise, the widget will **configure Amplify itself** using its default configuration.
181
+
182
+ ---
183
+
169
184
  ## 🎨 Assets & Styling
170
185
 
171
186
  The library bundles icons, background artwork, and shared CSS under `@snugdesk/whatsapp-widget/assets`. To make them available during your build, add the folder to the Angular CLI asset list:
@@ -142,6 +142,10 @@ class AppSyncGraphqlService {
142
142
  if (this.configured) {
143
143
  return;
144
144
  }
145
+ if (this.shouldUseHostConfig()) {
146
+ this.configured = true;
147
+ return;
148
+ }
145
149
  if (!this.config?.endpoint || !this.config?.region) {
146
150
  throw new Error('AppSync GraphQL configuration is missing.');
147
151
  }
@@ -165,6 +169,11 @@ class AppSyncGraphqlService {
165
169
  });
166
170
  this.configured = true;
167
171
  }
172
+ shouldUseHostConfig() {
173
+ const existing = Amplify.getConfig?.() ?? {};
174
+ const existingEndpoint = existing?.API?.GraphQL?.endpoint ?? existing?.API?.GraphQL?.graphql_endpoint ?? existing?.aws_appsync_graphqlEndpoint;
175
+ return existingEndpoint === defaultAppSyncConfig.endpoint;
176
+ }
168
177
  buildAuthHeaders() {
169
178
  const token = this.getToken();
170
179
  if (!token) {