nucleus-core-ts 0.10.38 → 0.10.39

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/.build-ok CHANGED
@@ -1 +1 @@
1
- 0.10.38
1
+ 0.10.39
@@ -4,6 +4,7 @@ import { addEdge, applyEdgeChanges, applyNodeChanges, Background, Controls, Mark
4
4
  import '@xyflow/react/dist/style.css';
5
5
  import { useEffect, useEffectEvent, useRef, useState } from 'react';
6
6
  import { cn } from '../../../utils/cn';
7
+ import { newId } from '../../../utils/newId';
7
8
  import { DEFAULT_VERIFICATION_FLOW_LABELS, setActiveLabels } from '../labels';
8
9
  import { useVerificationFlowStore } from '../store';
9
10
  import { getVerificationFlowTheme } from '../theme';
@@ -393,7 +394,7 @@ export function VerificationFlowPage({ entityName, title, subtitle, flowListActi
393
394
  if (!flowSaveAction) return;
394
395
  let flowId = store.selectedFlowId;
395
396
  if (!flowId) {
396
- flowId = crypto.randomUUID();
397
+ flowId = newId();
397
398
  store.setSelectedFlowId(flowId);
398
399
  }
399
400
  const name = flowName || say.defaultFlowName(entityName);
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A v4 UUID that also exists over plain HTTP.
3
+ *
4
+ * `crypto.randomUUID` is restricted to secure contexts: HTTPS, or localhost.
5
+ * Serve the same bundle from `http://something.example/` and the property is
6
+ * simply absent, so calling it throws `TypeError: crypto.randomUUID is not a
7
+ * function` — and it throws at the moment a user presses a button, inside a
8
+ * handler nobody wrapped, which is how a whole feature goes quiet with no error
9
+ * on screen.
10
+ *
11
+ * That is not hypothetical. The verification flow builder minted its flow id
12
+ * that way, and on a preview install served over HTTP the Save button did
13
+ * nothing at all: the exception landed before the save request was built, the
14
+ * canvas kept its unsaved graph, and the flow tables stayed empty. It looked
15
+ * like a backend that refused to persist.
16
+ *
17
+ * `crypto.getRandomValues` carries no such restriction — it is available in
18
+ * insecure contexts — so the fallback is still cryptographically random, and
19
+ * only the very last resort is not. Prefer this over `crypto.randomUUID`
20
+ * anywhere the code can run in a browser.
21
+ */
22
+ export declare function newId(): string;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * A v4 UUID that also exists over plain HTTP.
3
+ *
4
+ * `crypto.randomUUID` is restricted to secure contexts: HTTPS, or localhost.
5
+ * Serve the same bundle from `http://something.example/` and the property is
6
+ * simply absent, so calling it throws `TypeError: crypto.randomUUID is not a
7
+ * function` — and it throws at the moment a user presses a button, inside a
8
+ * handler nobody wrapped, which is how a whole feature goes quiet with no error
9
+ * on screen.
10
+ *
11
+ * That is not hypothetical. The verification flow builder minted its flow id
12
+ * that way, and on a preview install served over HTTP the Save button did
13
+ * nothing at all: the exception landed before the save request was built, the
14
+ * canvas kept its unsaved graph, and the flow tables stayed empty. It looked
15
+ * like a backend that refused to persist.
16
+ *
17
+ * `crypto.getRandomValues` carries no such restriction — it is available in
18
+ * insecure contexts — so the fallback is still cryptographically random, and
19
+ * only the very last resort is not. Prefer this over `crypto.randomUUID`
20
+ * anywhere the code can run in a browser.
21
+ */ export function newId() {
22
+ const c = typeof globalThis !== 'undefined' ? globalThis.crypto : undefined;
23
+ if (c && typeof c.randomUUID === 'function') {
24
+ return c.randomUUID();
25
+ }
26
+ const bytes = new Uint8Array(16);
27
+ if (c && typeof c.getRandomValues === 'function') {
28
+ c.getRandomValues(bytes);
29
+ } else {
30
+ // No Web Crypto at all (an ancient or stripped-down environment). The ids
31
+ // only have to be unique within one editing session, so this is enough to
32
+ // keep the feature working — but it is not a source of secrets, and nothing
33
+ // here should ever be used as one.
34
+ for(let i = 0; i < bytes.length; i++){
35
+ bytes[i] = Math.floor(Math.random() * 256);
36
+ }
37
+ }
38
+ // RFC 4122 §4.4: version 4, variant 10xx. `at()` rather than `bytes[i]`
39
+ // because the package compiles under noUncheckedIndexedAccess.
40
+ bytes[6] = (bytes.at(6) ?? 0) & 0x0f | 0x40;
41
+ bytes[8] = (bytes.at(8) ?? 0) & 0x3f | 0x80;
42
+ let hex = '';
43
+ for(let i = 0; i < bytes.length; i++){
44
+ if (i === 4 || i === 6 || i === 8 || i === 10) hex += '-';
45
+ hex += (bytes.at(i) ?? 0).toString(16).padStart(2, '0');
46
+ }
47
+ return hex;
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nucleus-core-ts",
3
- "version": "0.10.38",
3
+ "version": "0.10.39",
4
4
  "description": "Production-ready, enterprise-grade TypeScript framework for building multi-tenant APIs",
5
5
  "author": "Hidayet Can Özcan <hidayetcan@gmail.com>",
6
6
  "license": "SEE LICENSE IN LICENSE",