@calimero-network/mero-js 25.0.4 → 25.0.5

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.
@@ -1,3 +1,4 @@
1
+ import { pathSegment } from '../http-client/path-segment.js';
1
2
  export class AuthApiClient {
2
3
  constructor(httpClient) {
3
4
  this.httpClient = httpClient;
@@ -89,7 +90,7 @@ export class AuthApiClient {
89
90
  return response.data;
90
91
  }
91
92
  async deleteRootKey(keyId) {
92
- return this.httpClient.delete(`/admin/keys/${keyId}`);
93
+ return this.httpClient.delete(`/admin/keys/${pathSegment(keyId)}`);
93
94
  }
94
95
  // Client Management Endpoints
95
96
  async listClientKeys() {
@@ -103,14 +104,14 @@ export class AuthApiClient {
103
104
  return this.httpClient.post('/admin/client-key', request);
104
105
  }
105
106
  async deleteClientKey(keyId, clientId) {
106
- return this.httpClient.delete(`/admin/keys/${keyId}/clients/${clientId}`);
107
+ return this.httpClient.delete(`/admin/keys/${pathSegment(keyId)}/clients/${pathSegment(clientId)}`);
107
108
  }
108
109
  // Permission Management Endpoints
109
110
  async getKeyPermissions(keyId) {
110
- return this.httpClient.get(`/admin/keys/${keyId}/permissions`);
111
+ return this.httpClient.get(`/admin/keys/${pathSegment(keyId)}/permissions`);
111
112
  }
112
113
  async updateKeyPermissions(keyId, changes) {
113
114
  // Core expects an { add, remove } delta, not a { permissions } replacement.
114
- return this.httpClient.put(`/admin/keys/${keyId}/permissions`, { add: changes.add, remove: changes.remove });
115
+ return this.httpClient.put(`/admin/keys/${pathSegment(keyId)}/permissions`, { add: changes.add, remove: changes.remove });
115
116
  }
116
117
  }
@@ -27,6 +27,7 @@
27
27
  import { signAccountHaClaim } from './account-ownership.js';
28
28
  import { resolveRoot, resolveRootPair, signAccountLink, signAccountLogin, } from '../account/index.js';
29
29
  import { HTTPError } from '../http-client/web-client.js';
30
+ import { pathSegment } from '../http-client/path-segment.js';
30
31
  import { ACCOUNT_HEX, beginLinkState, takeLinkState } from './link-state.js';
31
32
  import { routingProofHeaders, } from './routing-proof.js';
32
33
  /**
@@ -352,7 +353,7 @@ export class CloudClient {
352
353
  * monotonic sequence on it.
353
354
  */
354
355
  async getNamespaceRelays(namespaceId) {
355
- const body = await this.request('GET', `/api/cloud/me/namespaces/${encodeURIComponent(namespaceId)}/relays`);
356
+ const body = await this.request('GET', `/api/cloud/me/namespaces/${pathSegment(namespaceId)}/relays`);
356
357
  return (body.relays ?? []).map((row) => {
357
358
  const relayUrl = row.relay_url ?? null;
358
359
  const executorAccount = row.executor_account ?? null;
@@ -408,7 +409,7 @@ export class CloudClient {
408
409
  * a node holding the namespace, so there is no hosted admitter.
409
410
  */
410
411
  async getNamespaceRouting(namespaceId) {
411
- const body = await this.request('GET', `/api/cloud/namespaces/${encodeURIComponent(namespaceId)}/admitters`, {
412
+ const body = await this.request('GET', `/api/cloud/namespaces/${pathSegment(namespaceId)}/admitters`, {
412
413
  anonymous: true,
413
414
  headers: await this.routingProof(namespaceId),
414
415
  });
@@ -449,7 +450,7 @@ export class CloudClient {
449
450
  * challenge somewhere this client cannot reach the key.
450
451
  */
451
452
  async getRoutingChallenge(namespaceId) {
452
- const body = await this.request('GET', `/api/cloud/namespaces/${encodeURIComponent(namespaceId)}/challenge`, {
453
+ const body = await this.request('GET', `/api/cloud/namespaces/${pathSegment(namespaceId)}/challenge`, {
453
454
  anonymous: true,
454
455
  });
455
456
  return {
@@ -481,7 +482,7 @@ export class CloudClient {
481
482
  * the account from the certificate and refuses a mismatch.
482
483
  */
483
484
  async getAccountRelaysChallenge(accountId) {
484
- const body = await this.request('GET', `/api/cloud/accounts/${encodeURIComponent(accountId)}/challenge`, {
485
+ const body = await this.request('GET', `/api/cloud/accounts/${pathSegment(accountId)}/challenge`, {
485
486
  anonymous: true,
486
487
  });
487
488
  return {
@@ -516,7 +517,7 @@ export class CloudClient {
516
517
  'certificate and its signing secret, since this read is proven by the device, not by a session.');
517
518
  }
518
519
  const challenge = await this.getAccountRelaysChallenge(accountId);
519
- const body = await this.request('GET', `/api/cloud/accounts/${encodeURIComponent(accountId)}/relays`, {
520
+ const body = await this.request('GET', `/api/cloud/accounts/${pathSegment(accountId)}/relays`, {
520
521
  anonymous: true,
521
522
  headers: await routingProofHeaders(challenge, this.routingCredential),
522
523
  });
@@ -633,7 +634,7 @@ export class CloudClient {
633
634
  const body = options.admitterAddrs === undefined
634
635
  ? {}
635
636
  : { admitter_addrs: [...options.admitterAddrs] };
636
- return this.request('POST', `/api/cloud/namespaces/${encodeURIComponent(namespaceId)}/enable-ha`, { body });
637
+ return this.request('POST', `/api/cloud/namespaces/${pathSegment(namespaceId)}/enable-ha`, { body });
637
638
  }
638
639
  /**
639
640
  * Enable HA for a namespace this ACCOUNT founded through a relay, with the
@@ -642,7 +643,7 @@ export class CloudClient {
642
643
  * The login must be linked to that account.
643
644
  */
644
645
  async enableFoundedNamespaceHa(namespaceId, ownershipProof) {
645
- return this.request('POST', `/api/cloud/me/namespaces/${encodeURIComponent(namespaceId)}/enable-ha`, { body: { groups: [], ownership_proof: ownershipProof } });
646
+ return this.request('POST', `/api/cloud/me/namespaces/${pathSegment(namespaceId)}/enable-ha`, { body: { groups: [], ownership_proof: ownershipProof } });
646
647
  }
647
648
  /**
648
649
  * Enable HA for a namespace this account founded, with **no cloud session**.
@@ -677,7 +678,7 @@ export class CloudClient {
677
678
  const account = options.accountId.toLowerCase();
678
679
  const namespace = options.namespaceId.toLowerCase();
679
680
  try {
680
- return await this.request('POST', `/api/cloud/accounts/${encodeURIComponent(account)}/namespaces/${encodeURIComponent(namespace)}/enable-ha`, { body: { ownership_proof: proof }, anonymous: true });
681
+ return await this.request('POST', `/api/cloud/accounts/${pathSegment(account)}/namespaces/${pathSegment(namespace)}/enable-ha`, { body: { ownership_proof: proof }, anonymous: true });
681
682
  }
682
683
  catch (err) {
683
684
  if (err instanceof HTTPError && ACCOUNT_HA_REFUSALS[err.status]) {
@@ -699,7 +700,7 @@ export class CloudClient {
699
700
  * billing flip.
700
701
  */
701
702
  async disableNamespaceHa(namespaceId) {
702
- return this.request('POST', `/api/cloud/namespaces/${encodeURIComponent(namespaceId)}/disable-ha`, { body: {} });
703
+ return this.request('POST', `/api/cloud/namespaces/${pathSegment(namespaceId)}/disable-ha`, { body: {} });
703
704
  }
704
705
  /**
705
706
  * The node assigned to the signed-in user, or `null`.
@@ -0,0 +1 @@
1
+ export declare function pathSegment(id: string): string;
@@ -0,0 +1,8 @@
1
+ // encodeURIComponent leaves "." and ".." intact and URL parsers collapse them,
2
+ // so those (and the empty id, which names the collection route) are refused.
3
+ export function pathSegment(id) {
4
+ if (id === '' || id === '.' || id === '..') {
5
+ throw new TypeError(`invalid request path segment: ${JSON.stringify(id)}`);
6
+ }
7
+ return encodeURIComponent(id);
8
+ }