@crimson-education/browser-logger 3.0.2 → 3.0.3-pinpoint-proxy.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 (39) hide show
  1. package/README.md +8 -2
  2. package/lib/index.d.ts +12 -12
  3. package/lib/index.js +69 -69
  4. package/lib/logger/consoleTransport.d.ts +36 -36
  5. package/lib/logger/consoleTransport.js +80 -80
  6. package/lib/logger/datadogTransport.d.ts +7 -7
  7. package/lib/logger/datadogTransport.js +20 -20
  8. package/lib/logger/index.d.ts +15 -15
  9. package/lib/logger/index.js +147 -147
  10. package/lib/logger/index.test.d.ts +1 -1
  11. package/lib/logger/index.test.js +59 -59
  12. package/lib/logger/utils.d.ts +14 -14
  13. package/lib/logger/utils.js +31 -31
  14. package/lib/reporters/amplifyReporter.d.ts +85 -83
  15. package/lib/reporters/amplifyReporter.d.ts.map +1 -1
  16. package/lib/reporters/amplifyReporter.js +198 -162
  17. package/lib/reporters/amplifyReporter.js.map +1 -1
  18. package/lib/reporters/amplifyReporter.test.d.ts +1 -1
  19. package/lib/reporters/amplifyReporter.test.js +50 -50
  20. package/lib/reporters/datadogReporter.d.ts +85 -85
  21. package/lib/reporters/datadogReporter.js +124 -124
  22. package/lib/reporters/gtmReporter.d.ts +8 -8
  23. package/lib/reporters/gtmReporter.js +56 -56
  24. package/lib/reporters/index.d.ts +66 -66
  25. package/lib/reporters/index.js +212 -212
  26. package/lib/reporters/logReporter.d.ts +34 -34
  27. package/lib/reporters/logReporter.js +61 -61
  28. package/lib/types/index.d.ts +2 -2
  29. package/lib/types/index.js +18 -18
  30. package/lib/types/logger.d.ts +77 -77
  31. package/lib/types/logger.js +10 -10
  32. package/lib/types/reporter.d.ts +154 -154
  33. package/lib/types/reporter.js +2 -2
  34. package/lib/utils.d.ts +9 -9
  35. package/lib/utils.js +31 -31
  36. package/lib/utils.test.d.ts +1 -1
  37. package/lib/utils.test.js +31 -31
  38. package/package.json +1 -1
  39. package/src/reporters/amplifyReporter.ts +51 -2
package/lib/utils.test.js CHANGED
@@ -1,32 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("./utils");
4
- describe('utils', () => {
5
- describe('filterReporterMetadata', () => {
6
- it('should remove attributes which match the ignore patterns', () => {
7
- const inputAttributeMap = {
8
- includeme: '5',
9
- excludeme: 'false',
10
- differentProp: 'boo',
11
- deep: {
12
- includeme: '5',
13
- excludeme: 'false',
14
- deepExcludeStr: 'boo',
15
- deepExcludeRegex: 'boo',
16
- },
17
- };
18
- const filtered = (0, utils_1.filterReporterMetadata)(inputAttributeMap, {
19
- ignoreMetadataPatterns: [/excludeme/g, /Prop/g, 'deep.deepExcludeStr', /deep\.deepExcludeRegex/g],
20
- });
21
- expect(filtered.includeme).toBeTruthy();
22
- expect(filtered.excludeme).toBeFalsy();
23
- expect(filtered.differentProp).toBeFalsy();
24
- // deep
25
- expect(filtered.deep.includeme).toBeTruthy();
26
- expect(filtered.deep.excludeme).toBeFalsy();
27
- expect(filtered.deep.deepExcludeStr).toBeFalsy();
28
- expect(filtered.deep.deepExcludeRegex).toBeFalsy();
29
- });
30
- });
31
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("./utils");
4
+ describe('utils', () => {
5
+ describe('filterReporterMetadata', () => {
6
+ it('should remove attributes which match the ignore patterns', () => {
7
+ const inputAttributeMap = {
8
+ includeme: '5',
9
+ excludeme: 'false',
10
+ differentProp: 'boo',
11
+ deep: {
12
+ includeme: '5',
13
+ excludeme: 'false',
14
+ deepExcludeStr: 'boo',
15
+ deepExcludeRegex: 'boo',
16
+ },
17
+ };
18
+ const filtered = (0, utils_1.filterReporterMetadata)(inputAttributeMap, {
19
+ ignoreMetadataPatterns: [/excludeme/g, /Prop/g, 'deep.deepExcludeStr', /deep\.deepExcludeRegex/g],
20
+ });
21
+ expect(filtered.includeme).toBeTruthy();
22
+ expect(filtered.excludeme).toBeFalsy();
23
+ expect(filtered.differentProp).toBeFalsy();
24
+ // deep
25
+ expect(filtered.deep.includeme).toBeTruthy();
26
+ expect(filtered.deep.excludeme).toBeFalsy();
27
+ expect(filtered.deep.deepExcludeStr).toBeFalsy();
28
+ expect(filtered.deep.deepExcludeRegex).toBeFalsy();
29
+ });
30
+ });
31
+ });
32
32
  //# sourceMappingURL=utils.test.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crimson-education/browser-logger",
3
- "version": "3.0.2",
3
+ "version": "3.0.3-pinpoint-proxy.1",
4
4
  "description": "An abstract logger and reporting utility for browser environments",
5
5
  "scripts": {
6
6
  "prepack": "npm run build",
@@ -1,3 +1,9 @@
1
+ import { Auth } from '@aws-amplify/auth';
2
+ import { Analytics } from '@aws-amplify/analytics';
3
+ import { Endpoint } from '@aws-sdk/types';
4
+ import { HttpRequest } from '@aws-sdk/protocol-http';
5
+ import { PinpointClient } from '@aws-sdk/client-pinpoint';
6
+
1
7
  import {
2
8
  IReporter,
3
9
  Metadata,
@@ -7,8 +13,6 @@ import {
7
13
  ReportUser,
8
14
  ServiceInfo,
9
15
  } from '../types';
10
- import { Auth } from '@aws-amplify/auth';
11
- import { Analytics } from '@aws-amplify/analytics';
12
16
  import { logger } from '../logger';
13
17
 
14
18
  /* eslint-disable @typescript-eslint/no-unused-vars */
@@ -30,6 +34,8 @@ export interface AmplifyReporterConfig extends ReporterConfigBase {
30
34
  * The Pinpoint App Id to report to.
31
35
  */
32
36
  analyticsAppId: string;
37
+ /** Optional proxy URL */
38
+ proxyUrl?: string;
33
39
  /**
34
40
  * The Cognito User Pool to configure in Auth.configure.
35
41
  * If you are using Cognito, it is better to set identityPoolId to false and configure Auth manually.
@@ -147,6 +153,49 @@ export function amplifyReporter(info: ServiceInfo, config: AmplifyReporterConfig
147
153
  });
148
154
  }
149
155
 
156
+ if (config.proxyUrl) {
157
+ // No public API for overriding where the Pinpoint client sends events to... 🤮
158
+ // Pinpoint client isn't available synchronously because it is instantiated when events get sent out,
159
+ // and then reinstantiated whenever the API credentials change. We need to hook `_initClients` to ensure
160
+ // that the Pinpoint client being used is always patched with our custom endpoint.
161
+ const provider = (Analytics.getPluggable('AWSPinpoint') as any)?.pinpointClient as any;
162
+ if (provider) {
163
+ const proxyUrl = new URL(config.proxyUrl);
164
+ if (typeof provider._initClients === 'function') {
165
+ const originalInitClients = provider._initClients;
166
+ provider._initClients = async (credentials: unknown) => {
167
+ const result = await originalInitClients._initClients(credentials);
168
+ const pinpointClient = provider.pinpointClient as PinpointClient | undefined;
169
+
170
+ if (pinpointClient) {
171
+ pinpointClient.config.endpoint = (): Promise<Endpoint> =>
172
+ Promise.resolve({
173
+ hostname: proxyUrl.hostname,
174
+ // Passing proxyUrl.pathname here doesn't work; it gets overridden
175
+ path: '/',
176
+ port: undefined,
177
+ protocol: proxyUrl.protocol,
178
+ });
179
+
180
+ pinpointClient.middlewareStack.add(
181
+ (next) => (args) => {
182
+ // Add proxyUrl.pathname to final request url if it was provided
183
+ if (proxyUrl.pathname !== '/' && HttpRequest.isInstance(args.request)) {
184
+ const shouldStripSlash = proxyUrl.pathname.startsWith('/');
185
+ args.request.path = `${proxyUrl.pathname}${args.request.path.slice(shouldStripSlash ? 1 : 0)}`;
186
+ }
187
+
188
+ return next(args);
189
+ },
190
+ { step: 'finalizeRequest' },
191
+ );
192
+ }
193
+ return result;
194
+ };
195
+ }
196
+ }
197
+ }
198
+
150
199
  const reporter: IReporter = {
151
200
  trackEvent: function (event: ReporterEvent): void {
152
201
  Analytics.record({