@terminal3/seal-web 0.2.0 → 0.3.0

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/README.md CHANGED
@@ -138,7 +138,7 @@ A field sealed to the customer reaches the recipient agent as `customer_jwe` in
138
138
 
139
139
  ## Elements
140
140
 
141
- - `<t3-safebox ref="sealed:…" label="…">` shows a sealed item once the customer opens it, for a minute. `auto-open` opens it on connection; `source="name"` fetches it from `api.sources.name`. An item with a `confirm` button fires `seal-confirmed` after the `confirm` endpoint answers, or `seal-confirm` (with `run_id`) for a confirmation your app runs itself.
141
+ - `<t3-safebox ref="sealed:…" label="…">` shows a sealed item once the customer opens it, for a minute. `auto-open` opens it on connection; `source="name"` fetches it from `api.sources.name`. An item with a `confirm` button fires `seal-confirmed` after the `confirm` endpoint answers, or `seal-confirm` (with `run_id`) for a confirmation your app runs itself. `decline-label="…"` adds a second button beside an item's own confirmation (not a `run_id` one): it fires `seal-declined` with the reference and records nothing, so your app decides what a decline means.
142
142
  - `<t3-safebox-form ref="request:…">` draws a sealed request from its verified description, and fires `seal-submitted` once the answers are sent.
143
143
  - Both may be in the page before `configure` runs: they wait in `data-state="waiting"` and start once it has. Both render again on each later `configure`; their shadow root keeps the mode it was attached with.
144
144
  - Both reflect their state in `data-state`, and take their accent colour from the CSS custom properties `--seal-accent` and `--seal-accent-soft`.
package/dist/elements.js CHANGED
@@ -1,6 +1,8 @@
1
- // <t3-safebox ref="sealed:…" label="…" source="…" auto-open>: a sealed item,
2
- // opened only in this browser and dropped from the page a minute later, or
3
- // as soon as the element leaves the page.
1
+ // <t3-safebox ref="sealed:…" label="…" source="…" decline-label="…" auto-open>:
2
+ // a sealed item, opened only in this browser and dropped from the page a
3
+ // minute later, or as soon as the element leaves the page. An item with a
4
+ // confirmation of its own (any `confirm.kind` but "run") also offers
5
+ // `decline-label`'s button, when the page sets one.
4
6
  // <t3-safebox-form ref="request:…">: a sealed request, drawn from its signed
5
7
  // description. Both wait in `data-state="waiting"` until `configure` has run,
6
8
  // then render into a shadow root of the configured mode, attached once, and
@@ -38,7 +40,8 @@ const STYLE = `
38
40
  .f span{color:#7a7a82;font-size:12.5px}
39
41
  .f b{font-weight:600;text-align:right}
40
42
  .mono{font-family:ui-monospace,"SF Mono",Menlo,monospace;letter-spacing:.02em}
41
- .row{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:12px}
43
+ .row{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:12px;flex-wrap:wrap}
44
+ .acts{display:flex;gap:8px;margin-left:auto}
42
45
  button{font:inherit;font-weight:600;border-radius:10px;padding:8px 14px;cursor:pointer;border:0;background:var(--seal-accent,#c8102e);color:#fff}
43
46
  button.ghost{background:#fff;color:#1d1d1f;border:1px solid #d9d3cd}
44
47
  button:disabled{opacity:.55;cursor:default}
@@ -66,7 +69,7 @@ const rpName = () => configured()?.rpName ?? "";
66
69
  const shadowMode = () => configured()?.shadow ?? "closed";
67
70
  /** Defines both elements once; a no-op where they are already defined. */
68
71
  export function defineElements() {
69
- var _T3Safebox_root, _T3Safebox_unlisten, _T3Safebox_data, _T3Safebox_label, _T3Safebox_confirmed, _T3Safebox_error, _T3Safebox_hideTimer, _T3SafeboxForm_root, _T3SafeboxForm_unlisten, _T3SafeboxForm_desc, _T3SafeboxForm_files, _T3SafeboxForm_error;
72
+ var _T3Safebox_root, _T3Safebox_unlisten, _T3Safebox_data, _T3Safebox_label, _T3Safebox_confirmed, _T3Safebox_declined, _T3Safebox_confirming, _T3Safebox_error, _T3Safebox_hideTimer, _T3SafeboxForm_root, _T3SafeboxForm_unlisten, _T3SafeboxForm_desc, _T3SafeboxForm_files, _T3SafeboxForm_error;
70
73
  class T3Safebox extends HTMLElement {
71
74
  constructor() {
72
75
  super(...arguments);
@@ -75,6 +78,8 @@ export function defineElements() {
75
78
  _T3Safebox_data.set(this, null);
76
79
  _T3Safebox_label.set(this, null);
77
80
  _T3Safebox_confirmed.set(this, false);
81
+ _T3Safebox_declined.set(this, false);
82
+ _T3Safebox_confirming.set(this, false);
78
83
  _T3Safebox_error.set(this, null);
79
84
  _T3Safebox_hideTimer.set(this, void 0);
80
85
  }
@@ -122,9 +127,12 @@ export function defineElements() {
122
127
  }
123
128
  }
124
129
  async confirm() {
125
- const btn = __classPrivateFieldGet(this, _T3Safebox_root, "f")?.querySelector("#confirm");
126
- if (btn)
127
- btn.disabled = true;
130
+ __classPrivateFieldSet(this, _T3Safebox_confirming, true, "f");
131
+ for (const id of ["#confirm", "#decline"]) {
132
+ const btn = __classPrivateFieldGet(this, _T3Safebox_root, "f")?.querySelector(id);
133
+ if (btn)
134
+ btn.disabled = true;
135
+ }
128
136
  const c = __classPrivateFieldGet(this, _T3Safebox_data, "f")?.confirm ?? {};
129
137
  const ref = this.getAttribute("ref");
130
138
  try {
@@ -144,6 +152,18 @@ export function defineElements() {
144
152
  __classPrivateFieldSet(this, _T3Safebox_error, messageOf(e), "f");
145
153
  this.render();
146
154
  }
155
+ finally {
156
+ __classPrivateFieldSet(this, _T3Safebox_confirming, false, "f");
157
+ }
158
+ }
159
+ /** The customer's "not this one", for the app to act on: nothing is recorded in T3N. */
160
+ decline() {
161
+ if (__classPrivateFieldGet(this, _T3Safebox_confirming, "f") || __classPrivateFieldGet(this, _T3Safebox_confirmed, "f"))
162
+ return;
163
+ __classPrivateFieldSet(this, _T3Safebox_declined, true, "f");
164
+ this.setAttribute("data-declined", "true");
165
+ this.dispatchEvent(new CustomEvent("seal-declined", { bubbles: true, composed: true, detail: { ref: this.getAttribute("ref") } }));
166
+ this.render();
147
167
  }
148
168
  hide() {
149
169
  __classPrivateFieldSet(this, _T3Safebox_data, null, "f");
@@ -174,12 +194,14 @@ export function defineElements() {
174
194
  else if (d) {
175
195
  const fields = Array.isArray(d.fields) ? d.fields : [];
176
196
  const c = d.confirm;
197
+ const answered = __classPrivateFieldGet(this, _T3Safebox_confirmed, "f") || __classPrivateFieldGet(this, _T3Safebox_declined, "f");
198
+ const declineLabel = c?.kind !== "run" ? this.getAttribute("decline-label") : null;
177
199
  body = `${d.summary ? `<div class="sum">${esc(d.summary)}</div>` : ""}<div class="fields">${fields
178
200
  .map((f) => `<div class="f" data-field="${esc(f.label)}"><span>${esc(f.label)}</span><b class="${f.mono ? "mono" : ""}">${esc(f.value)}</b></div>`)
179
201
  .join("")}</div>
180
- ${__classPrivateFieldGet(this, _T3Safebox_confirmed, "f") ? `<div class="ok">Confirmed</div>` : ""}
202
+ ${__classPrivateFieldGet(this, _T3Safebox_confirmed, "f") ? `<div class="ok">Confirmed</div>` : __classPrivateFieldGet(this, _T3Safebox_declined, "f") ? `<div class="note">You said this is not the one.</div>` : ""}
181
203
  <div class="row"><span class="note">Decrypted in this browser only.</span>
182
- ${c && !__classPrivateFieldGet(this, _T3Safebox_confirmed, "f") ? `<button id="confirm">${esc(c.label ?? "Confirm")}</button>` : `<button class="ghost" id="hide">Hide</button>`}</div>`;
204
+ ${c && !answered ? `<span class="acts">${declineLabel ? `<button class="ghost" id="decline">${esc(declineLabel)}</button>` : ""}<button id="confirm">${esc(c.label ?? "Confirm")}</button></span>` : `<button class="ghost" id="hide">Hide</button>`}</div>`;
183
205
  }
184
206
  else if (state === "error") {
185
207
  body = `<div class="err">${esc(__classPrivateFieldGet(this, _T3Safebox_error, "f"))}</div><div class="row"><span class="note">Only this browser can open it.</span><button id="reveal">Open</button></div>`;
@@ -196,9 +218,10 @@ export function defineElements() {
196
218
  root.querySelector("#reveal")?.addEventListener("click", () => void this.reveal());
197
219
  root.querySelector("#hide")?.addEventListener("click", () => this.hide());
198
220
  root.querySelector("#confirm")?.addEventListener("click", () => void this.confirm());
221
+ root.querySelector("#decline")?.addEventListener("click", () => this.decline());
199
222
  }
200
223
  }
201
- _T3Safebox_root = new WeakMap(), _T3Safebox_unlisten = new WeakMap(), _T3Safebox_data = new WeakMap(), _T3Safebox_label = new WeakMap(), _T3Safebox_confirmed = new WeakMap(), _T3Safebox_error = new WeakMap(), _T3Safebox_hideTimer = new WeakMap();
224
+ _T3Safebox_root = new WeakMap(), _T3Safebox_unlisten = new WeakMap(), _T3Safebox_data = new WeakMap(), _T3Safebox_label = new WeakMap(), _T3Safebox_confirmed = new WeakMap(), _T3Safebox_declined = new WeakMap(), _T3Safebox_confirming = new WeakMap(), _T3Safebox_error = new WeakMap(), _T3Safebox_hideTimer = new WeakMap();
202
225
  class T3SafeboxForm extends HTMLElement {
203
226
  constructor() {
204
227
  super(...arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terminal3/seal-web",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "T3n sealed delivery in the browser - open items sealed to a device-bound key, and fill signed forms whose answers only their named recipients can read, with no runtime dependencies",
6
6
  "main": "dist/index.js",