@amos.com/amos-js 0.10.4 → 0.10.6

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.
package/dist/types.d.ts CHANGED
@@ -267,16 +267,6 @@ export type Message = {
267
267
  requestId: string;
268
268
  link_token?: string;
269
269
  error?: string;
270
- } | {
271
- /**
272
- * Parent → embed: info telemetry for Rollbar. The iframe reports
273
- * `message` with `endpoint`, `headers`, and `body`.
274
- */
275
- type: "PARENT_INFO_LOG";
276
- message: string;
277
- endpoint?: string;
278
- headers?: Record<string, string>;
279
- body?: unknown;
280
270
  };
281
271
  /**
282
272
  * Identity helper that brands an object as a typed `Message`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amos.com/amos-js",
3
- "version": "0.10.4",
3
+ "version": "0.10.6",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",
package/src/apple-pay.ts CHANGED
@@ -132,6 +132,9 @@ export function attachApplePayButtonListeners(
132
132
  ...options,
133
133
  height,
134
134
  };
135
+ // React calls `update()` on first paint, before the iframe has left
136
+ // about:blank. Queue until IFRAME_READY so postMessage targetOrigin matches.
137
+ let ready = false;
135
138
 
136
139
  function pushAmount() {
137
140
  sendUpdateAmount({ iframe, amount: current.amount });
@@ -157,6 +160,7 @@ export function attachApplePayButtonListeners(
157
160
 
158
161
  switch (event.data.type) {
159
162
  case "IFRAME_READY":
163
+ ready = true;
160
164
  sendParentReadyMessage(iframe);
161
165
  sendUpdateAppearance({ iframe, appearance: {} });
162
166
  pushAmount();
@@ -224,6 +228,9 @@ export function attachApplePayButtonListeners(
224
228
  const hadMerchantName = "merchantName" in patch;
225
229
  const hadButtonProps = "height" in patch || "buttonProps" in patch;
226
230
  current = { ...current, ...patch };
231
+ if (!ready) {
232
+ return;
233
+ }
227
234
  if (hadAmount) {
228
235
  pushAmount();
229
236
  }
package/src/google-pay.ts CHANGED
@@ -118,6 +118,9 @@ export function attachGooglePayButtonListeners(
118
118
  ...options,
119
119
  height,
120
120
  };
121
+ // React calls `update()` on first paint, before the iframe has left
122
+ // about:blank. Queue until IFRAME_READY so postMessage targetOrigin matches.
123
+ let ready = false;
121
124
 
122
125
  function pushAmount() {
123
126
  sendUpdateAmount({ iframe, amount: current.amount });
@@ -142,6 +145,7 @@ export function attachGooglePayButtonListeners(
142
145
 
143
146
  switch (event.data.type) {
144
147
  case "IFRAME_READY":
148
+ ready = true;
145
149
  sendParentReadyMessage(iframe);
146
150
  sendUpdateAppearance({ iframe, appearance: {} });
147
151
  pushAmount();
@@ -194,6 +198,9 @@ export function attachGooglePayButtonListeners(
194
198
  const hadMerchantName = "merchantName" in patch;
195
199
  const hadButtonProps = "height" in patch || "buttonProps" in patch;
196
200
  current = { ...current, ...patch };
201
+ if (!ready) {
202
+ return;
203
+ }
197
204
  if (hadAmount) {
198
205
  pushAmount();
199
206
  }
package/src/messaging.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { components } from "@amos.com/node";
2
2
  import { decodeJwt } from "./jwt";
3
- import { reportParentInfoLog } from "./log";
4
3
  import { getBankPlaidSession } from "./plaid-session";
5
4
  import {
6
5
  type Appearance,
@@ -293,24 +292,6 @@ function postConfirmIntent({
293
292
  resetIframeFields(iframe);
294
293
  }
295
294
 
296
- const origin = getIframeTargetOrigin(iframe);
297
- reportParentInfoLog({
298
- iframe,
299
- message:
300
- type === "CONFIRM_PAYMENT_INTENT"
301
- ? "confirmPaymentIntent"
302
- : "confirmSetupIntent",
303
- endpoint:
304
- type === "CONFIRM_PAYMENT_INTENT"
305
- ? "POST /embed/payment_intents/{id}/confirm_with_payment_method"
306
- : "POST /embed/setup_intents/{id}/confirm_with_payment_method",
307
- headers: {
308
- origin: window.location.origin,
309
- "iframe-origin": origin,
310
- },
311
- body: { id, token, ...(plaid ? { plaid } : {}) },
312
- });
313
-
314
295
  iframe.contentWindow?.postMessage(
315
296
  createMessage({
316
297
  type,
@@ -194,6 +194,9 @@ export function attachPaymentMethodFormListeners(
194
194
  options: PaymentMethodFormListenerOptions,
195
195
  ): PaymentMethodFormController {
196
196
  let current = { ...options };
197
+ // React calls `update()` on first paint, before the iframe has left
198
+ // about:blank. Queue until IFRAME_READY so postMessage targetOrigin matches.
199
+ let ready = false;
197
200
 
198
201
  function handleMessage(event: MessageEvent<Message>) {
199
202
  if (event.source !== iframe.contentWindow) {
@@ -202,6 +205,7 @@ export function attachPaymentMethodFormListeners(
202
205
 
203
206
  switch (event.data.type) {
204
207
  case "IFRAME_READY":
208
+ ready = true;
205
209
  sendParentReadyMessage(iframe);
206
210
  sendUpdateAppearance({ iframe, appearance: current.appearance });
207
211
  break;
@@ -241,7 +245,7 @@ export function attachPaymentMethodFormListeners(
241
245
  update(patch) {
242
246
  const hadAppearance = "appearance" in patch;
243
247
  current = { ...current, ...patch };
244
- if (hadAppearance) {
248
+ if (hadAppearance && ready) {
245
249
  sendUpdateAppearance({ iframe, appearance: current.appearance });
246
250
  }
247
251
  },
@@ -1,4 +1,3 @@
1
- import { reportParentInfoLog } from "./log";
2
1
  import { requestPlaidLinkToken } from "./messaging";
3
2
  import type { PaymentMethodFormListenerOptions } from "./payment-method-form";
4
3
  import {
@@ -310,16 +309,6 @@ export function attachPlaidBankUi({
310
309
  thresholdKnown = true;
311
310
  achThreshold = event.data.achThreshold ?? undefined;
312
311
  requireVerification = event.data.requireVerification === true;
313
- reportParentInfoLog({
314
- iframe,
315
- message: "merchant ach_threshold",
316
- endpoint: "ACH_THRESHOLD",
317
- headers: { origin: event.origin },
318
- body: {
319
- achThreshold,
320
- requireVerification,
321
- },
322
- });
323
312
  if (linked && !requiresConnect()) {
324
313
  unlink();
325
314
  return;
package/src/types.ts CHANGED
@@ -557,17 +557,6 @@ export type Message =
557
557
  requestId: string;
558
558
  link_token?: string;
559
559
  error?: string;
560
- }
561
- | {
562
- /**
563
- * Parent → embed: info telemetry for Rollbar. The iframe reports
564
- * `message` with `endpoint`, `headers`, and `body`.
565
- */
566
- type: "PARENT_INFO_LOG";
567
- message: string;
568
- endpoint?: string;
569
- headers?: Record<string, string>;
570
- body?: unknown;
571
560
  };
572
561
 
573
562
  /**
package/dist/log.d.ts DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * Forward an info log to the embed iframe so Rollbar records it with
3
- * Amos credentials. Payload shape matches dashboard/embed API traces:
4
- * `endpoint`, `headers`, `body`.
5
- */
6
- export declare function reportParentInfoLog({ iframe, message, endpoint, headers, body, }: {
7
- iframe: HTMLIFrameElement;
8
- message: string;
9
- endpoint: string;
10
- headers?: Record<string, string>;
11
- body?: unknown;
12
- }): void;
package/src/log.ts DELETED
@@ -1,74 +0,0 @@
1
- import { createMessage } from "./types";
2
-
3
- const SENSITIVE_HEADER_NAMES = new Set([
4
- "authorization",
5
- "cookie",
6
- "set-cookie",
7
- "x-api-key",
8
- ]);
9
-
10
- const SENSITIVE_BODY_KEYS = new Set([
11
- "authorization",
12
- "encrypted_account_number",
13
- "link_token",
14
- "public_token",
15
- "token",
16
- ]);
17
-
18
- function redactHeaders(
19
- headers: Record<string, string>,
20
- ): Record<string, string> {
21
- const redacted: Record<string, string> = {};
22
- for (const [key, value] of Object.entries(headers)) {
23
- redacted[key] = SENSITIVE_HEADER_NAMES.has(key.toLowerCase())
24
- ? "[REDACTED]"
25
- : value;
26
- }
27
- return redacted;
28
- }
29
-
30
- function redactBody(body: unknown): unknown {
31
- if (Array.isArray(body)) {
32
- return body.map(redactBody);
33
- }
34
- if (body !== null && typeof body === "object") {
35
- const redacted: Record<string, unknown> = {};
36
- for (const [key, value] of Object.entries(body)) {
37
- redacted[key] = SENSITIVE_BODY_KEYS.has(key)
38
- ? "[REDACTED]"
39
- : redactBody(value);
40
- }
41
- return redacted;
42
- }
43
- return body;
44
- }
45
-
46
- /**
47
- * Forward an info log to the embed iframe so Rollbar records it with
48
- * Amos credentials. Payload shape matches dashboard/embed API traces:
49
- * `endpoint`, `headers`, `body`.
50
- */
51
- export function reportParentInfoLog({
52
- iframe,
53
- message,
54
- endpoint,
55
- headers = {},
56
- body,
57
- }: {
58
- iframe: HTMLIFrameElement;
59
- message: string;
60
- endpoint: string;
61
- headers?: Record<string, string>;
62
- body?: unknown;
63
- }): void {
64
- iframe.contentWindow?.postMessage(
65
- createMessage({
66
- type: "PARENT_INFO_LOG",
67
- message,
68
- endpoint,
69
- headers: redactHeaders(headers),
70
- body: redactBody(body),
71
- }),
72
- new URL(iframe.src).origin,
73
- );
74
- }