@juspay/neurolink 11.29.2 → 11.30.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/dist/auth/anthropicOAuth.d.ts +50 -0
  3. package/dist/auth/anthropicOAuth.js +78 -0
  4. package/dist/browser/neurolink.min.js +393 -393
  5. package/dist/cli/commands/proxy.d.ts +2 -0
  6. package/dist/cli/commands/proxy.js +284 -4
  7. package/dist/cli/commands/proxyExpose.d.ts +35 -0
  8. package/dist/cli/commands/proxyExpose.js +252 -0
  9. package/dist/cli/commands/proxyPeer.d.ts +29 -0
  10. package/dist/cli/commands/proxyPeer.js +738 -0
  11. package/dist/cli/commands/proxyShare.d.ts +37 -0
  12. package/dist/cli/commands/proxyShare.js +1080 -0
  13. package/dist/cli/parser.js +7 -1
  14. package/dist/proxy/peerStore.d.ts +52 -0
  15. package/dist/proxy/peerStore.js +324 -0
  16. package/dist/proxy/peerTransport.d.ts +38 -0
  17. package/dist/proxy/peerTransport.js +242 -0
  18. package/dist/proxy/proxyPaths.d.ts +8 -0
  19. package/dist/proxy/proxyPaths.js +55 -17
  20. package/dist/proxy/requestLogger.js +8 -0
  21. package/dist/proxy/residentGrants.d.ts +57 -0
  22. package/dist/proxy/residentGrants.js +393 -0
  23. package/dist/proxy/shareAudit.d.ts +81 -0
  24. package/dist/proxy/shareAudit.js +280 -0
  25. package/dist/proxy/shareContext.d.ts +38 -0
  26. package/dist/proxy/shareContext.js +92 -0
  27. package/dist/proxy/shareGate.d.ts +64 -0
  28. package/dist/proxy/shareGate.js +216 -0
  29. package/dist/proxy/shareGrants.d.ts +115 -0
  30. package/dist/proxy/shareGrants.js +590 -0
  31. package/dist/proxy/shareLease.d.ts +101 -0
  32. package/dist/proxy/shareLease.js +192 -0
  33. package/dist/proxy/shareLedger.d.ts +105 -0
  34. package/dist/proxy/shareLedger.js +406 -0
  35. package/dist/proxy/shareListener.d.ts +60 -0
  36. package/dist/proxy/shareListener.js +143 -0
  37. package/dist/proxy/shareNotes.d.ts +97 -0
  38. package/dist/proxy/shareNotes.js +234 -0
  39. package/dist/proxy/sharePolicy.d.ts +110 -0
  40. package/dist/proxy/sharePolicy.js +366 -0
  41. package/dist/proxy/shareProvisioning.d.ts +110 -0
  42. package/dist/proxy/shareProvisioning.js +237 -0
  43. package/dist/proxy/shareReceipts.d.ts +99 -0
  44. package/dist/proxy/shareReceipts.js +303 -0
  45. package/dist/proxy/shareSigning.d.ts +40 -0
  46. package/dist/proxy/shareSigning.js +78 -0
  47. package/dist/server/routes/claudeProxyRoutes.js +1066 -3
  48. package/dist/types/cli.d.ts +61 -0
  49. package/dist/types/proxy.d.ts +781 -0
  50. package/package.json +2 -1
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Peer-sharing grant store.
3
+ *
4
+ * A grant is one lender-issued, revocable authorization for one borrower. This
5
+ * module owns the persisted grant file and the token contract; it deliberately
6
+ * knows nothing about admission policy (see `sharePolicy.ts`) or transport.
7
+ *
8
+ * **Token contract.** A share token looks like `nls_<grantId>_<secret>`. The
9
+ * grant id is carried in the token so a lookup is a map hit rather than a scan
10
+ * over every grant, and only then is the secret compared — in constant time —
11
+ * against `sha256(salt + secret)`. The raw token exists exactly once, in the
12
+ * return value of `createShareGrant`; nothing persists it.
13
+ *
14
+ * **Cross-process freshness.** The CLI mutates this file in one process while
15
+ * the proxy reads it in another, so `share pause` has to land in a running
16
+ * proxy without a restart. Reads therefore re-stat the file and reload when its
17
+ * mtime moves, bounded by a short TTL so the hot path pays one `stat` per
18
+ * second at most.
19
+ *
20
+ * @module proxy/shareGrants
21
+ */
22
+ import type { ProxyShareGrant, ProxyShareGrantInput, ProxyShareGrantPatch, ProxyShareGrantState, ProxyShareIssuedGrant } from "../types/index.js";
23
+ /** Token prefix. Distinguishes a share token from a client's own credential. */
24
+ export declare const SHARE_TOKEN_PREFIX = "nls";
25
+ /** Point the store at an explicit file. Used by dev mode and by tests. */
26
+ export declare function initShareGrants(grantsFilePath: string): void;
27
+ /**
28
+ * This node's stable public address.
29
+ *
30
+ * Recorded once — by `share url`, or by whatever already fronts this proxy — so
31
+ * a link can be minted without retyping the domain. Nothing here assumes the
32
+ * address came from `proxy expose`; a reverse proxy, a permanent named tunnel
33
+ * or a plain DNS record are all the same thing to a borrower.
34
+ */
35
+ export declare function getNodePublicUrl(): Promise<string | undefined>;
36
+ export declare function setNodePublicUrl(url: string | undefined): Promise<void>;
37
+ /**
38
+ * Split a share token into its grant id and secret.
39
+ * Returns null for anything that is not one of our tokens — including a client's
40
+ * own Anthropic credential, which must never be mistaken for a share token.
41
+ */
42
+ export declare function parseShareToken(token: string): {
43
+ grantId: string;
44
+ secret: string;
45
+ } | null;
46
+ export declare function looksLikeShareToken(token: string | undefined): boolean;
47
+ export declare function listShareGrants(): Promise<ProxyShareGrant[]>;
48
+ export declare function getShareGrant(id: string): Promise<ProxyShareGrant | undefined>;
49
+ /** Look a grant up by peer label (case-insensitive), the CLI's addressing form. */
50
+ export declare function findShareGrantByPeer(peerLabel: string): Promise<ProxyShareGrant | undefined>;
51
+ export declare function createShareGrant(input: ProxyShareGrantInput): Promise<ProxyShareIssuedGrant>;
52
+ /**
53
+ * Replace a grant's token, keeping every control intact.
54
+ * Used by `share revoke --rotate` and by any suspected token leak.
55
+ */
56
+ export declare function rotateShareGrantToken(id: string): Promise<ProxyShareIssuedGrant | undefined>;
57
+ export declare function setShareGrantState(id: string, state: ProxyShareGrantState): Promise<ProxyShareGrant | undefined>;
58
+ export declare function updateShareGrant(id: string, patch: ProxyShareGrantPatch): Promise<ProxyShareGrant | undefined>;
59
+ /**
60
+ * Attach complete-mode lease material to a grant.
61
+ *
62
+ * Separate from `updateShareGrant` because these are not policy the operator
63
+ * edits — the secret is generated once and the borrower's copy is keyed to it,
64
+ * so overwriting it silently would invalidate every lease already in the field.
65
+ */
66
+ export declare function attachLeaseMaterial(id: string, leaseSecret: string, leasePolicy: {
67
+ ttlMs: number;
68
+ heartbeatEveryMs: number;
69
+ offlineGraceMs: number;
70
+ }, provisionedAccount?: string): Promise<ProxyShareGrant | undefined>;
71
+ /**
72
+ * Subtract settled spend from a metered grant's balance.
73
+ *
74
+ * Read-modify-write **inside** the store's mutex, because settlement is
75
+ * concurrent by nature: two streams finishing together would otherwise both read
76
+ * the same balance, and the second write would erase the first one's deduction.
77
+ * Returns the new balance, or `undefined` for a grant that is not metered.
78
+ */
79
+ export declare function debitShareGrantCoins(id: string, coins: number): Promise<number | undefined>;
80
+ /**
81
+ * Add coins to a metered grant's balance.
82
+ *
83
+ * The mirror of `debitShareGrantCoins`, and under the same lock for the same
84
+ * reason. Used by reciprocal netting, by `share topup`'s successor paths, and by
85
+ * redeeming a coin note — all of which can land while requests are settling.
86
+ */
87
+ export declare function creditShareGrantCoins(id: string, coins: number): Promise<number | undefined>;
88
+ /**
89
+ * This node's secret for signing coin notes.
90
+ *
91
+ * Node-level rather than per-grant: a note may be redeemed by a grant that did
92
+ * not exist when it was issued, which is the entire point of a transferable
93
+ * one. Minted on first use so a node that never issues a note never has one.
94
+ */
95
+ export declare function getOrCreateNoteSecret(): Promise<string>;
96
+ /** The note secret, without minting one. */
97
+ export declare function getNoteSecret(): Promise<string | undefined>;
98
+ export declare function deleteShareGrant(id: string): Promise<boolean>;
99
+ /**
100
+ * Resolve a presented token to its grant.
101
+ *
102
+ * Returns the grant whatever its state — admission is `sharePolicy`'s decision,
103
+ * and a paused grant must still be identifiable so the refusal can say *why*
104
+ * rather than "unknown token".
105
+ */
106
+ export declare function resolveShareToken(token: string): Promise<ProxyShareGrant | undefined>;
107
+ /**
108
+ * Record that a grant served traffic.
109
+ *
110
+ * `lastUsedAt` is cosmetic, so it is held in memory and flushed at most once a
111
+ * minute. Persisting it per request would put a file write on the hot path and —
112
+ * worse — move the file's mtime constantly, forcing every reader to reload the
113
+ * snapshot it just loaded.
114
+ */
115
+ export declare function touchShareGrantUsage(id: string): void;