@nevermined-io/payments 1.9.0 → 1.11.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 (98) hide show
  1. package/dist/api/base-payments.d.ts +11 -0
  2. package/dist/api/base-payments.d.ts.map +1 -1
  3. package/dist/api/base-payments.js +28 -3
  4. package/dist/api/base-payments.js.map +1 -1
  5. package/dist/api/nvm-api.d.ts +4 -0
  6. package/dist/api/nvm-api.d.ts.map +1 -1
  7. package/dist/api/nvm-api.js +7 -0
  8. package/dist/api/nvm-api.js.map +1 -1
  9. package/dist/api/organizations-api/organizations-api.d.ts +19 -1
  10. package/dist/api/organizations-api/organizations-api.d.ts.map +1 -1
  11. package/dist/api/organizations-api/organizations-api.js +49 -0
  12. package/dist/api/organizations-api/organizations-api.js.map +1 -1
  13. package/dist/api/organizations-api/types.d.ts +27 -0
  14. package/dist/api/organizations-api/types.d.ts.map +1 -1
  15. package/dist/api/organizations-api/types.js.map +1 -1
  16. package/dist/common/api-version.d.ts +1 -1
  17. package/dist/common/api-version.js +1 -1
  18. package/dist/common/api-version.js.map +1 -1
  19. package/dist/common/types.d.ts +9 -4
  20. package/dist/common/types.d.ts.map +1 -1
  21. package/dist/common/types.js.map +1 -1
  22. package/dist/environments.d.ts +12 -0
  23. package/dist/environments.d.ts.map +1 -1
  24. package/dist/environments.js +31 -0
  25. package/dist/environments.js.map +1 -1
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +2 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/mcp/core/server-manager.d.ts.map +1 -1
  31. package/dist/mcp/core/server-manager.js +3 -0
  32. package/dist/mcp/core/server-manager.js.map +1 -1
  33. package/dist/mcp/http/mcp-handler.d.ts +7 -0
  34. package/dist/mcp/http/mcp-handler.d.ts.map +1 -1
  35. package/dist/mcp/http/mcp-handler.js +8 -1
  36. package/dist/mcp/http/mcp-handler.js.map +1 -1
  37. package/dist/mcp/http/oauth-metadata.d.ts.map +1 -1
  38. package/dist/mcp/http/oauth-metadata.js +31 -6
  39. package/dist/mcp/http/oauth-metadata.js.map +1 -1
  40. package/dist/mcp/http/oauth-router.d.ts +17 -16
  41. package/dist/mcp/http/oauth-router.d.ts.map +1 -1
  42. package/dist/mcp/http/oauth-router.js +56 -28
  43. package/dist/mcp/http/oauth-router.js.map +1 -1
  44. package/dist/mpp/codec.d.ts +92 -0
  45. package/dist/mpp/codec.d.ts.map +1 -0
  46. package/dist/mpp/codec.js +405 -0
  47. package/dist/mpp/codec.js.map +1 -0
  48. package/dist/mpp/errors.d.ts +165 -0
  49. package/dist/mpp/errors.d.ts.map +1 -0
  50. package/dist/mpp/errors.js +177 -0
  51. package/dist/mpp/errors.js.map +1 -0
  52. package/dist/mpp/fetch.d.ts +196 -0
  53. package/dist/mpp/fetch.d.ts.map +1 -0
  54. package/dist/mpp/fetch.js +493 -0
  55. package/dist/mpp/fetch.js.map +1 -0
  56. package/dist/mpp/index.d.ts +11 -0
  57. package/dist/mpp/index.d.ts.map +1 -0
  58. package/dist/mpp/index.js +20 -0
  59. package/dist/mpp/index.js.map +1 -0
  60. package/dist/mpp/mpp-api.d.ts +153 -0
  61. package/dist/mpp/mpp-api.d.ts.map +1 -0
  62. package/dist/mpp/mpp-api.js +298 -0
  63. package/dist/mpp/mpp-api.js.map +1 -0
  64. package/dist/mpp/types.d.ts +43 -0
  65. package/dist/mpp/types.d.ts.map +1 -0
  66. package/dist/mpp/types.js +9 -0
  67. package/dist/mpp/types.js.map +1 -0
  68. package/dist/payments.d.ts +13 -0
  69. package/dist/payments.d.ts.map +1 -1
  70. package/dist/payments.js +3 -0
  71. package/dist/payments.js.map +1 -1
  72. package/dist/x402/delegation-api.d.ts +3 -1
  73. package/dist/x402/delegation-api.d.ts.map +1 -1
  74. package/dist/x402/delegation-api.js.map +1 -1
  75. package/dist/x402/express/index.d.ts +2 -0
  76. package/dist/x402/express/index.d.ts.map +1 -1
  77. package/dist/x402/express/index.js +2 -0
  78. package/dist/x402/express/index.js.map +1 -1
  79. package/dist/x402/express/middleware.d.ts +33 -1
  80. package/dist/x402/express/middleware.d.ts.map +1 -1
  81. package/dist/x402/express/middleware.js +831 -1
  82. package/dist/x402/express/middleware.js.map +1 -1
  83. package/dist/x402/express/mpp-support.d.ts +58 -0
  84. package/dist/x402/express/mpp-support.d.ts.map +1 -0
  85. package/dist/x402/express/mpp-support.js +67 -0
  86. package/dist/x402/express/mpp-support.js.map +1 -0
  87. package/dist/x402/express/raw-body.d.ts +24 -0
  88. package/dist/x402/express/raw-body.d.ts.map +1 -0
  89. package/dist/x402/express/raw-body.js +34 -0
  90. package/dist/x402/express/raw-body.js.map +1 -0
  91. package/dist/x402/token-request.d.ts +15 -0
  92. package/dist/x402/token-request.d.ts.map +1 -0
  93. package/dist/x402/token-request.js +66 -0
  94. package/dist/x402/token-request.js.map +1 -0
  95. package/dist/x402/token.d.ts.map +1 -1
  96. package/dist/x402/token.js +7 -51
  97. package/dist/x402/token.js.map +1 -1
  98. package/package.json +3 -1
@@ -49,6 +49,17 @@ export declare abstract class BasePaymentsAPI {
49
49
  protected currentOrganizationId: string | null;
50
50
  isBrowserInstance: boolean;
51
51
  constructor(options: PaymentOptions);
52
+ /**
53
+ * Resolves the active environment for this instance.
54
+ *
55
+ * The environment is derived from the NVM API key prefix
56
+ * (`<prefix>:<jwt>`); the key wins whenever its prefix is recognized. The
57
+ * deprecated `environment` option is still honored as a fallback when the
58
+ * key has no recognized prefix (e.g. local/custom dev), and ultimately
59
+ * defaults to `custom`. Passing `environment` emits a one-time deprecation
60
+ * warning.
61
+ */
62
+ private resolveEnvironmentName;
52
63
  /**
53
64
  * Parses the NVM API Key to extract the account address.
54
65
  * @throws PaymentsError if the API key is invalid.
@@ -1 +1 @@
1
- {"version":3,"file":"base-payments.d.ts","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,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AAE,MAAM,CAAA;IAC1B,SAAS,CAAC,cAAc,EAAE,MAAM,CAAA;IAChC,SAAS,CAAC,cAAc,EAAE,MAAM,CAAA;IAChC,SAAS,CAAC,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAA;IACvC,iBAAiB,UAAO;gBAEnB,OAAO,EAAE,cAAc;IAmCnC;;;;;;;;;OASG;IACH,OAAO,CAAC,sBAAsB;IAkB9B;;;OAGG;IACH,SAAS,CAAC,cAAc,IAAI;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE;IAc9E;;;OAGG;IACI,kBAAkB,IAAI,eAAe;IAI5C;;;OAGG;IACI,iBAAiB,IAAI,MAAM,GAAG,SAAS;IAI9C;;;;;;OAMG;IACI,iBAAiB,IAAI,MAAM,GAAG,IAAI;IAIzC;;;;;;;OAOG;IACI,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAI7D;;;;;;;;;OASG;IACH,SAAS,CAAC,qBAAqB,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,GAAG,EACV,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IA4BvC;;;;;;;;OAQG;IACH,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG;gBAE7C,MAAM;iBACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;eACxB,MAAM;;CAgBlB"}
@@ -2,7 +2,10 @@ import { decodeJwt } from 'jose';
2
2
  import { API_VERSION_HEADER, LOCKED_API_VERSION } from '../common/api-version.js';
3
3
  import { jsonReplacer } from '../common/helper.js';
4
4
  import { PaymentsError } from '../common/payments.error.js';
5
- import { Environments } from '../environments.js';
5
+ import { Environments, getEnvironmentFromApiKey, } from '../environments.js';
6
+ // Emit the `environment` deprecation notice at most once per process to avoid
7
+ // log spam when many sub-API instances are constructed from the same options.
8
+ let environmentOptionDeprecationWarned = false;
6
9
  /**
7
10
  * Header used by the Nevermined backend to resolve the active organization
8
11
  * context for an authenticated request. Resolution priority is:
@@ -47,8 +50,8 @@ export class BasePaymentsAPI {
47
50
  this.nvmApiKey = options.nvmApiKey;
48
51
  this.scheme = options.scheme || 'nvm';
49
52
  this.returnUrl = options.returnUrl || '';
50
- this.environment = Environments[options.environment];
51
- this.environmentName = options.environment;
53
+ this.environmentName = this.resolveEnvironmentName(options);
54
+ this.environment = Environments[this.environmentName];
52
55
  this.appId = options.appId;
53
56
  // `version` is the backend API pin (MAJOR.MINOR) sent verbatim as
54
57
  // Nevermined-Version. Fail fast on a malformed value rather than shipping
@@ -63,6 +66,28 @@ export class BasePaymentsAPI {
63
66
  this.accountAddress = accountAddress;
64
67
  this.heliconeApiKey = heliconeApiKey;
65
68
  }
69
+ /**
70
+ * Resolves the active environment for this instance.
71
+ *
72
+ * The environment is derived from the NVM API key prefix
73
+ * (`<prefix>:<jwt>`); the key wins whenever its prefix is recognized. The
74
+ * deprecated `environment` option is still honored as a fallback when the
75
+ * key has no recognized prefix (e.g. local/custom dev), and ultimately
76
+ * defaults to `custom`. Passing `environment` emits a one-time deprecation
77
+ * warning.
78
+ */
79
+ resolveEnvironmentName(options) {
80
+ const fromKey = getEnvironmentFromApiKey(options.nvmApiKey);
81
+ if (options.environment && !environmentOptionDeprecationWarned) {
82
+ environmentOptionDeprecationWarned = true;
83
+ const override = fromKey && fromKey !== options.environment
84
+ ? ` It is ignored in favor of the environment derived from the API key ('${fromKey}').`
85
+ : '';
86
+ console.warn("[DEPRECATED] The 'environment' option is deprecated; the environment is now derived " +
87
+ `from the NVM API key prefix.${override} Remove the 'environment' option to silence this warning.`);
88
+ }
89
+ return fromKey ?? options.environment ?? 'custom';
90
+ }
66
91
  /**
67
92
  * Parses the NVM API Key to extract the account address.
68
93
  * @throws PaymentsError if the API key is invalid.
@@ -1 +1 @@
1
- {"version":3,"file":"base-payments.js","sourceRoot":"","sources":["../../src/api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AAc,EAAE,IAAU;QACvD,MAAM,OAAO,GAIT;YACF,MAAM;YACN,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;gBAClC,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,OAAO,IAAI,kBAAkB;aACzD;SACF,CAAA;QAED,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { decodeJwt } from 'jose'\nimport { API_VERSION_HEADER, LOCKED_API_VERSION } from '../common/api-version.js'\nimport { jsonReplacer } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { PaymentOptions, PaymentScheme } from '../common/types.js'\nimport { EnvironmentInfo, EnvironmentName, Environments } from '../environments.js'\n\n/**\n * Header used by the Nevermined backend to resolve the active organization\n * context for an authenticated request. Resolution priority is:\n * path `:orgId` &gt; this header &gt; API-key tag &gt; fallback membership &gt; personal.\n * See `apps/api/src/common/guards/current-org-context.guard.ts` in nvm-monorepo.\n */\nexport const CURRENT_ORG_ID_HEADER = 'X-Current-Org-Id'\n\n/**\n * Set of header names that callers can pass to `getBackendHTTPOptions` via\n * `extraHeaders`. Anything outside this set is dropped silently so a stray\n * `Authorization` or `Content-Type` override can't clobber the SDK's\n * transport security headers.\n */\nconst ALLOWED_EXTRA_HEADERS = new Set<string>([CURRENT_ORG_ID_HEADER])\n\n/**\n * Options accepted by publication methods (`registerAgent`,\n * `registerAgentAndPlan`, `registerPlan`, …) that want to override the\n * active organization workspace for a single call.\n */\nexport type PublicationOptions = {\n /**\n * Organization id (e.g. `org-…`) to publish into. When set, the SDK\n * sends an `X-Current-Org-Id` header for this call only — the caller's\n * instance-level pin (set via `Payments.setOrganizationId`) is not\n * affected.\n */\n organizationId?: string\n}\n\n/**\n * Builds the `extraHeaders` argument for `getBackendHTTPOptions` from\n * publication options. Returns `undefined` when no override is requested\n * so existing callers receive identical request shapes.\n */\nexport function resolvePublicationHeaders(\n options?: PublicationOptions,\n): Record<string, string> | undefined {\n if (options?.organizationId) {\n return { [CURRENT_ORG_ID_HEADER]: options.organizationId }\n }\n return undefined\n}\n\n/**\n * Base class extended by all Payments API classes.\n * It provides common functionality such as parsing the NVM API Key and getting the account address.\n */\nexport abstract class BasePaymentsAPI {\n protected nvmApiKey: string\n protected scheme: PaymentScheme\n protected environment: EnvironmentInfo\n protected environmentName: EnvironmentName\n protected returnUrl: string\n protected appId?: string\n /**\n * Backend API version (MAJOR.MINOR) pinned by this instance, set from\n * `options.version`. When unset, every request defaults to\n * {@link LOCKED_API_VERSION}.\n */\n protected version?: string\n protected accountAddress: string\n protected heliconeApiKey: string\n protected currentOrganizationId: string | null\n public isBrowserInstance = true\n\n constructor(options: PaymentOptions) {\n // Type-level narrowing of PaymentScheme to 'nvm' won't protect callers\n // pinned to an older .d.ts that still has 'visa' in the union — they\n // would silently fall through to the standard pipeline and hit a\n // misleading 'Invalid NVM API Key' from parseNvmApiKey when the\n // legacy Visa path tolerated a non-JWT key. Reject up front with a\n // clear migration message.\n if (options.scheme && options.scheme !== 'nvm') {\n throw new PaymentsError(\n `scheme '${options.scheme}' is no longer supported. Visa is now exposed as provider:'visa' on createDelegation; construct Payments without a scheme override.`,\n )\n }\n this.nvmApiKey = options.nvmApiKey\n this.scheme = options.scheme || 'nvm'\n this.returnUrl = options.returnUrl || ''\n this.environment = Environments[options.environment as EnvironmentName]\n this.environmentName = options.environment\n this.appId = options.appId\n // `version` is the backend API pin (MAJOR.MINOR) sent verbatim as\n // Nevermined-Version. Fail fast on a malformed value rather than shipping\n // an invalid header (e.g. an SDK package version '1.0.0', 'v1.1', or '')\n // that the backend rejects with 400 on every call.\n if (options.version !== undefined && !/^\\d+\\.\\d+$/.test(options.version)) {\n throw new PaymentsError(\n `Invalid 'version' option '${options.version}': expected a backend API version as MAJOR.MINOR (e.g. '1.1'). Omit it to use the SDK's default pin.`,\n )\n }\n this.version = options.version\n this.currentOrganizationId = options.organizationId ?? null\n\n const { accountAddress, heliconeApiKey } = this.parseNvmApiKey()\n this.accountAddress = accountAddress\n this.heliconeApiKey = heliconeApiKey\n }\n\n /**\n * Parses the NVM API Key to extract the account address.\n * @throws PaymentsError if the API key is invalid.\n */\n protected parseNvmApiKey(): { accountAddress: string; heliconeApiKey: string } {\n try {\n if (!this.nvmApiKey) {\n throw new PaymentsError('NVM API Key is required')\n }\n const jwt = decodeJwt(this.nvmApiKey)\n const accountAddress = jwt.sub as string\n const heliconeApiKey = jwt.o11y as string\n return { accountAddress, heliconeApiKey }\n } catch (error) {\n throw new PaymentsError('Invalid NVM API Key')\n }\n }\n\n /**\n * Returns the environment name used to initialize the Payments instance.\n * @returns The environment name (e.g. 'sandbox', 'live')\n */\n public getEnvironmentName(): EnvironmentName {\n return this.environmentName\n }\n\n /**\n * It returns the account address associated with the NVM API Key used to initialize the Payments Library instance.\n * @returns The account address extracted from the NVM API Key\n */\n public getAccountAddress(): string | undefined {\n return this.accountAddress\n }\n\n /**\n * Returns the current organization context applied to every authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * `null` means \"no pinned workspace\" — the backend falls back to the\n * caller's API-key tag or most-recent active membership.\n */\n public getOrganizationId(): string | null {\n return this.currentOrganizationId\n }\n\n /**\n * Sets the organization context applied to every subsequent authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * Pass `null` to clear the pin and fall back to the backend default.\n *\n * @param organizationId - Org ID (e.g. `org-…`) or `null` to clear.\n */\n public setOrganizationId(organizationId: string | null): void {\n this.currentOrganizationId = organizationId\n }\n\n /**\n * Returns the HTTP options required to query the backend.\n * @param method - HTTP method.\n * @param body - Optional request body.\n * @param extraHeaders - Optional per-call header overrides. Use\n * `{ 'X-Current-Org-Id': orgId }` to target a specific workspace for\n * one call without mutating the instance-level pin.\n * @returns HTTP options object.\n * @internal\n */\n protected getBackendHTTPOptions(\n method: string,\n body?: any,\n extraHeaders?: Record<string, string>,\n ) {\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.nvmApiKey}`,\n [API_VERSION_HEADER]: this.version ?? LOCKED_API_VERSION,\n }\n if (this.currentOrganizationId) {\n headers[CURRENT_ORG_ID_HEADER] = this.currentOrganizationId\n }\n if (extraHeaders) {\n // Allowlist callers' header overrides so a passed-in `Authorization`\n // or `Content-Type` can't clobber the SDK's transport security\n // headers. Today only `X-Current-Org-Id` is allowed through.\n for (const [name, value] of Object.entries(extraHeaders)) {\n if (ALLOWED_EXTRA_HEADERS.has(name)) {\n headers[name] = value\n }\n }\n }\n return {\n method,\n headers,\n ...(body && { body: JSON.stringify(body, jsonReplacer) }),\n }\n }\n\n /**\n * Get HTTP options for public backend requests (no authorization header).\n * Converts body keys from snake_case to camelCase for consistency.\n *\n * @param method - HTTP method\n * @param body - Optional request body (keys will be converted to camelCase)\n * @returns HTTP options object\n * @internal\n */\n protected getPublicHTTPOptions(method: string, body?: any) {\n const options: {\n method: string\n headers: Record<string, string>\n body?: string\n } = {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n [API_VERSION_HEADER]: this.version ?? LOCKED_API_VERSION,\n },\n }\n\n if (body) {\n options.body = JSON.stringify(body, jsonReplacer)\n }\n\n return options\n }\n}\n"]}
1
+ {"version":3,"file":"base-payments.js","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,EAGL,YAAY,EACZ,wBAAwB,GACzB,MAAM,oBAAoB,CAAA;AAE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AAC,EAAE,CAAC;oBACpC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;gBACvB,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO;YACL,MAAM;YACN,OAAO;YACP,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC;SAC1D,CAAA;IACH,CAAC;IAED;;;;;;;;OAQG;IACO,oBAAoB,CAAC,MAAc,EAAE,IAAU;QACvD,MAAM,OAAO,GAIT;YACF,MAAM;YACN,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;gBAClC,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,OAAO,IAAI,kBAAkB;aACzD;SACF,CAAA;QAED,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { decodeJwt } from 'jose'\nimport { API_VERSION_HEADER, LOCKED_API_VERSION } from '../common/api-version.js'\nimport { jsonReplacer } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { PaymentOptions, PaymentScheme } from '../common/types.js'\nimport {\n EnvironmentInfo,\n EnvironmentName,\n Environments,\n getEnvironmentFromApiKey,\n} from '../environments.js'\n\n// Emit the `environment` deprecation notice at most once per process to avoid\n// log spam when many sub-API instances are constructed from the same options.\nlet environmentOptionDeprecationWarned = false\n\n/**\n * Header used by the Nevermined backend to resolve the active organization\n * context for an authenticated request. Resolution priority is:\n * path `:orgId` &gt; this header &gt; API-key tag &gt; fallback membership &gt; personal.\n * See `apps/api/src/common/guards/current-org-context.guard.ts` in nvm-monorepo.\n */\nexport const CURRENT_ORG_ID_HEADER = 'X-Current-Org-Id'\n\n/**\n * Set of header names that callers can pass to `getBackendHTTPOptions` via\n * `extraHeaders`. Anything outside this set is dropped silently so a stray\n * `Authorization` or `Content-Type` override can't clobber the SDK's\n * transport security headers.\n */\nconst ALLOWED_EXTRA_HEADERS = new Set<string>([CURRENT_ORG_ID_HEADER])\n\n/**\n * Options accepted by publication methods (`registerAgent`,\n * `registerAgentAndPlan`, `registerPlan`, …) that want to override the\n * active organization workspace for a single call.\n */\nexport type PublicationOptions = {\n /**\n * Organization id (e.g. `org-…`) to publish into. When set, the SDK\n * sends an `X-Current-Org-Id` header for this call only — the caller's\n * instance-level pin (set via `Payments.setOrganizationId`) is not\n * affected.\n */\n organizationId?: string\n}\n\n/**\n * Builds the `extraHeaders` argument for `getBackendHTTPOptions` from\n * publication options. Returns `undefined` when no override is requested\n * so existing callers receive identical request shapes.\n */\nexport function resolvePublicationHeaders(\n options?: PublicationOptions,\n): Record<string, string> | undefined {\n if (options?.organizationId) {\n return { [CURRENT_ORG_ID_HEADER]: options.organizationId }\n }\n return undefined\n}\n\n/**\n * Base class extended by all Payments API classes.\n * It provides common functionality such as parsing the NVM API Key and getting the account address.\n */\nexport abstract class BasePaymentsAPI {\n protected nvmApiKey: string\n protected scheme: PaymentScheme\n protected environment: EnvironmentInfo\n protected environmentName: EnvironmentName\n protected returnUrl: string\n protected appId?: string\n /**\n * Backend API version (MAJOR.MINOR) pinned by this instance, set from\n * `options.version`. When unset, every request defaults to\n * {@link LOCKED_API_VERSION}.\n */\n protected version?: string\n protected accountAddress: string\n protected heliconeApiKey: string\n protected currentOrganizationId: string | null\n public isBrowserInstance = true\n\n constructor(options: PaymentOptions) {\n // Type-level narrowing of PaymentScheme to 'nvm' won't protect callers\n // pinned to an older .d.ts that still has 'visa' in the union — they\n // would silently fall through to the standard pipeline and hit a\n // misleading 'Invalid NVM API Key' from parseNvmApiKey when the\n // legacy Visa path tolerated a non-JWT key. Reject up front with a\n // clear migration message.\n if (options.scheme && options.scheme !== 'nvm') {\n throw new PaymentsError(\n `scheme '${options.scheme}' is no longer supported. Visa is now exposed as provider:'visa' on createDelegation; construct Payments without a scheme override.`,\n )\n }\n this.nvmApiKey = options.nvmApiKey\n this.scheme = options.scheme || 'nvm'\n this.returnUrl = options.returnUrl || ''\n this.environmentName = this.resolveEnvironmentName(options)\n this.environment = Environments[this.environmentName]\n this.appId = options.appId\n // `version` is the backend API pin (MAJOR.MINOR) sent verbatim as\n // Nevermined-Version. Fail fast on a malformed value rather than shipping\n // an invalid header (e.g. an SDK package version '1.0.0', 'v1.1', or '')\n // that the backend rejects with 400 on every call.\n if (options.version !== undefined && !/^\\d+\\.\\d+$/.test(options.version)) {\n throw new PaymentsError(\n `Invalid 'version' option '${options.version}': expected a backend API version as MAJOR.MINOR (e.g. '1.1'). Omit it to use the SDK's default pin.`,\n )\n }\n this.version = options.version\n this.currentOrganizationId = options.organizationId ?? null\n\n const { accountAddress, heliconeApiKey } = this.parseNvmApiKey()\n this.accountAddress = accountAddress\n this.heliconeApiKey = heliconeApiKey\n }\n\n /**\n * Resolves the active environment for this instance.\n *\n * The environment is derived from the NVM API key prefix\n * (`<prefix>:<jwt>`); the key wins whenever its prefix is recognized. The\n * deprecated `environment` option is still honored as a fallback when the\n * key has no recognized prefix (e.g. local/custom dev), and ultimately\n * defaults to `custom`. Passing `environment` emits a one-time deprecation\n * warning.\n */\n private resolveEnvironmentName(options: PaymentOptions): EnvironmentName {\n const fromKey = getEnvironmentFromApiKey(options.nvmApiKey)\n\n if (options.environment && !environmentOptionDeprecationWarned) {\n environmentOptionDeprecationWarned = true\n const override =\n fromKey && fromKey !== options.environment\n ? ` It is ignored in favor of the environment derived from the API key ('${fromKey}').`\n : ''\n console.warn(\n \"[DEPRECATED] The 'environment' option is deprecated; the environment is now derived \" +\n `from the NVM API key prefix.${override} Remove the 'environment' option to silence this warning.`,\n )\n }\n\n return fromKey ?? options.environment ?? 'custom'\n }\n\n /**\n * Parses the NVM API Key to extract the account address.\n * @throws PaymentsError if the API key is invalid.\n */\n protected parseNvmApiKey(): { accountAddress: string; heliconeApiKey: string } {\n try {\n if (!this.nvmApiKey) {\n throw new PaymentsError('NVM API Key is required')\n }\n const jwt = decodeJwt(this.nvmApiKey)\n const accountAddress = jwt.sub as string\n const heliconeApiKey = jwt.o11y as string\n return { accountAddress, heliconeApiKey }\n } catch (error) {\n throw new PaymentsError('Invalid NVM API Key')\n }\n }\n\n /**\n * Returns the environment name used to initialize the Payments instance.\n * @returns The environment name (e.g. 'sandbox', 'live')\n */\n public getEnvironmentName(): EnvironmentName {\n return this.environmentName\n }\n\n /**\n * It returns the account address associated with the NVM API Key used to initialize the Payments Library instance.\n * @returns The account address extracted from the NVM API Key\n */\n public getAccountAddress(): string | undefined {\n return this.accountAddress\n }\n\n /**\n * Returns the current organization context applied to every authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * `null` means \"no pinned workspace\" — the backend falls back to the\n * caller's API-key tag or most-recent active membership.\n */\n public getOrganizationId(): string | null {\n return this.currentOrganizationId\n }\n\n /**\n * Sets the organization context applied to every subsequent authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * Pass `null` to clear the pin and fall back to the backend default.\n *\n * @param organizationId - Org ID (e.g. `org-…`) or `null` to clear.\n */\n public setOrganizationId(organizationId: string | null): void {\n this.currentOrganizationId = organizationId\n }\n\n /**\n * Returns the HTTP options required to query the backend.\n * @param method - HTTP method.\n * @param body - Optional request body.\n * @param extraHeaders - Optional per-call header overrides. Use\n * `{ 'X-Current-Org-Id': orgId }` to target a specific workspace for\n * one call without mutating the instance-level pin.\n * @returns HTTP options object.\n * @internal\n */\n protected getBackendHTTPOptions(\n method: string,\n body?: any,\n extraHeaders?: Record<string, string>,\n ) {\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.nvmApiKey}`,\n [API_VERSION_HEADER]: this.version ?? LOCKED_API_VERSION,\n }\n if (this.currentOrganizationId) {\n headers[CURRENT_ORG_ID_HEADER] = this.currentOrganizationId\n }\n if (extraHeaders) {\n // Allowlist callers' header overrides so a passed-in `Authorization`\n // or `Content-Type` can't clobber the SDK's transport security\n // headers. Today only `X-Current-Org-Id` is allowed through.\n for (const [name, value] of Object.entries(extraHeaders)) {\n if (ALLOWED_EXTRA_HEADERS.has(name)) {\n headers[name] = value\n }\n }\n }\n return {\n method,\n headers,\n ...(body && { body: JSON.stringify(body, jsonReplacer) }),\n }\n }\n\n /**\n * Get HTTP options for public backend requests (no authorization header).\n * Converts body keys from snake_case to camelCase for consistency.\n *\n * @param method - HTTP method\n * @param body - Optional request body (keys will be converted to camelCase)\n * @returns HTTP options object\n * @internal\n */\n protected getPublicHTTPOptions(method: string, body?: any) {\n const options: {\n method: string\n headers: Record<string, string>\n body?: string\n } = {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n [API_VERSION_HEADER]: this.version ?? LOCKED_API_VERSION,\n },\n }\n\n if (body) {\n options.body = JSON.stringify(body, jsonReplacer)\n }\n\n return options\n }\n}\n"]}
@@ -22,6 +22,10 @@ export declare const API_URL_VALIDATE_AGENT_ACCESS_TOKEN = "/api/v1/protocol/tok
22
22
  export declare const API_URL_CREATE_PERMISSION = "/api/v1/x402/permissions";
23
23
  export declare const API_URL_VERIFY_PERMISSIONS = "/api/v1/x402/verify";
24
24
  export declare const API_URL_SETTLE_PERMISSIONS = "/api/v1/x402/settle";
25
+ export declare const API_URL_MPP_CREATE_PERMISSION = "/api/v1/mpp/permissions";
26
+ export declare const API_URL_MPP_CHALLENGE = "/api/v1/mpp/challenge";
27
+ export declare const API_URL_MPP_VERIFY = "/api/v1/mpp/verify";
28
+ export declare const API_URL_MPP_SETTLE = "/api/v1/mpp/settle";
25
29
  export declare const API_URL_STRIPE_CHECKOUT = "/api/v1/fiat/stripe/payment";
26
30
  export declare const API_URL_CREATE_USER = "/api/v1/organizations/account";
27
31
  export declare const API_URL_GET_MEMBERS = "/api/v1/organizations/members";
@@ -1 +1 @@
1
- {"version":3,"file":"nvm-api.d.ts","sourceRoot":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E,UAAU,EAAE,kBAAkB;IAI3D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,kBAAkB;IAI1D,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,kBAAkB;CAGpE"}
@@ -26,6 +26,13 @@ export const API_URL_VALIDATE_AGENT_ACCESS_TOKEN = '/api/v1/protocol/token/valid
26
26
  export const API_URL_CREATE_PERMISSION = '/api/v1/x402/permissions';
27
27
  export const API_URL_VERIFY_PERMISSIONS = '/api/v1/x402/verify';
28
28
  export const API_URL_SETTLE_PERMISSIONS = '/api/v1/x402/settle';
29
+ // MPP seller/buyer surface. Sibling routes of /api/v1/x402, never children:
30
+ // an MPP access token is byte-identical to an x402 one on the wire, so the
31
+ // route is what fixes the protocol. See nvm-monorepo#2641.
32
+ export const API_URL_MPP_CREATE_PERMISSION = '/api/v1/mpp/permissions';
33
+ export const API_URL_MPP_CHALLENGE = '/api/v1/mpp/challenge';
34
+ export const API_URL_MPP_VERIFY = '/api/v1/mpp/verify';
35
+ export const API_URL_MPP_SETTLE = '/api/v1/mpp/settle';
29
36
  export const API_URL_STRIPE_CHECKOUT = '/api/v1/fiat/stripe/payment';
30
37
  export const API_URL_CREATE_USER = '/api/v1/organizations/account';
31
38
  export const API_URL_GET_MEMBERS = '/api/v1/organizations/members';
@@ -1 +1 @@
1
- {"version":3,"file":"nvm-api.js","sourceRoot":"","sources":["../../src/api/nvm-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAA;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,yBAAyB,CAAA;AAC/D,MAAM,CAAC,MAAM,gCAAgC,GAAG,+BAA+B,CAAA;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,kCAAkC,CAAA;AACnE,MAAM,CAAC,MA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ACxD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAW,EAAE,IAAS,EAAE,UAA8B;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IACpD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,IAAS,EAAE,UAA8B;QAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IACnD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,IAAS,EAAE,UAA8B;QACjE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IACtD,CAAC;CACF","sourcesContent":["import axios from 'axios'\n\nexport const API_URL_REGISTER_PLAN = '/api/v1/protocol/plans'\nexport const API_URL_REGISTER_AGENT = '/api/v1/protocol/agents'\nexport const API_URL_REGISTER_AGENTS_AND_PLAN = '/api/v1/protocol/agents/plans'\nexport const API_URL_GET_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_UPDATE_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_GET_AGENT_PLANS = '/api/v1/protocol/agents/:agentId/plans'\n// GET: the caller's own agents (?orgId= scopes to an org the caller belongs to).\n// Same path as API_URL_REGISTER_AGENT (disambiguated by GET vs POST); mirrors\n// the existing API_URL_REGISTER_PLAN / API_URL_GET_PLANS pair below.\nexport const API_URL_GET_AGENTS = '/api/v1/protocol/agents'\nexport const API_URL_GET_PLAN = '/api/v1/protocol/plans/:planId'\nexport const API_URL_GET_PLANS = '/api/v1/protocol/plans'\nexport const API_URL_GET_PLAN_AGENTS = '/api/v1/protocol/plans/:planId/agents'\nexport const API_URL_ORDER_PLAN = '/api/v1/protocol/plans/:planId/order'\nexport const API_URL_MINT_PLAN = '/api/v1/protocol/plans/mint'\nexport const API_URL_MINT_EXPIRABLE_PLAN = '/api/v1/protocol/plans/mintExpirable'\nexport const API_URL_ADD_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_REMOVE_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_PLAN_BALANCE = '/api/v1/protocol/plans/:planId/balance/:holderAddress'\nexport const API_URL_INITIALIZE_AGENT = '/api/v1/protocol/agents/initialize/:agentId'\nexport const API_URL_SIMULATE_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/start'\nexport const API_URL_SIMULATE_REDEEM_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/finish'\nexport const API_URL_TRACK_AGENT_SUB_TASK = '/api/v1/protocol/agent-sub-tasks'\nexport const API_URL_VALIDATE_AGENT_ACCESS_TOKEN = '/api/v1/protocol/token/validate/:agentId'\nexport const API_URL_CREATE_PERMISSION = '/api/v1/x402/permissions'\nexport const API_URL_VERIFY_PERMISSIONS = '/api/v1/x402/verify'\nexport const API_URL_SETTLE_PERMISSIONS = '/api/v1/x402/settle'\nexport const API_URL_STRIPE_CHECKOUT = '/api/v1/fiat/stripe/payment'\nexport const API_URL_CREATE_USER = '/api/v1/organizations/account'\nexport const API_URL_GET_MEMBERS = '/api/v1/organizations/members'\nexport const API_URL_MY_MEMBERSHIPS = '/api/v1/organizations/my-memberships'\nexport const API_URL_ORG_ACTIVITY = '/api/v1/organizations/:orgId/activity'\nexport const API_URL_CONNECT_STRIPE_ACCOUNT = '/api/v1/fiat/stripe/account'\n\nexport interface BackendApiOptions {\n /**\n * The host of the backend server\n */\n backendHost: string\n\n /**\n * The Nevermined API Key. This key identify your user and is required to interact with the Nevermined API.\n * You can get your API key by logging in to the Nevermined App.\n * @see https://nevermined.ai/docs/tutorials/integration/nvm-api-keys\n */\n apiKey?: string\n\n /**\n * The host of the Nevermined Proxy\n */\n proxyHost?: string\n\n /**\n * Additional headers to send with the requests\n */\n headers?: { [key: string]: string }\n}\n\nexport class HTTPRequestOptions {\n accessToken?: string\n sendThroughProxy = true\n proxyHost?: string = undefined\n headers?: { [key: string]: string } = {}\n}\n\nexport abstract class AbstractHTTPClient {\n // protected opts: BackendApiOptions\n // private hasKey = false\n // private agentId = ''\n\n // constructor(opts: BackendApiOptions) {\n // const defaultHeaders = {\n // Accept: 'application/json',\n // ...opts.headers,\n // ...(opts.apiKey && { Authorization: `Bearer ${opts.apiKey}` }),\n // }\n\n // this.opts = {\n // ...opts,\n // headers: defaultHeaders,\n // }\n\n // try {\n // if (this.opts.apiKey && this.opts.apiKey.length > 0) {\n // const jwt = decodeJwt(this.opts.apiKey)\n // if (isEthereumAddress(jwt.sub)) {\n // this.hasKey = true\n // }\n // }\n // } catch {\n // this.hasKey = false\n // }\n\n // let backendUrl\n // try {\n // backendUrl = new URL(this.opts.backendHost)\n // this.opts.backendHost = backendUrl.origin\n // } catch (error) {\n // throw new Error(`Invalid URL: ${this.opts.backendHost} - ${(error as Error).message}`)\n // }\n // }\n\n constructor() {\n // Empty constructor - required for abstract class implementation\n }\n\n parseUrl(urlRequested: string, reqOptions: HTTPRequestOptions) {\n let _host: URL\n if (reqOptions.sendThroughProxy) {\n if (!reqOptions.proxyHost)\n throw new Error('Proxy host is required when sendThroughProxy is true')\n return `${new URL(reqOptions.proxyHost).origin}${new URL(urlRequested).href}`\n } else {\n return urlRequested\n }\n }\n\n parseHeaders(requestHeaders: { [key: string]: string }, accessToken?: string) {\n return {\n ...(accessToken && { Authorization: `Bearer ${accessToken}` }),\n ...requestHeaders,\n }\n }\n\n // setBearerToken(token: string) {\n // this.opts.headers = {\n // ...this.opts.headers,\n // Authorization: `Bearer ${token}`,\n // }\n // }\n\n async request(\n method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',\n url: string,\n data?: any,\n reqOptions: HTTPRequestOptions = {\n sendThroughProxy: false,\n },\n ) {\n try {\n const response = await axios({\n method,\n url: this.parseUrl(url, reqOptions),\n headers: this.parseHeaders(reqOptions.headers || {}, reqOptions.accessToken),\n ...(data && { data }), // Only include `data` for methods that support it\n })\n\n return response\n } catch (err) {\n if (axios.isAxiosError(err) && err.response) {\n throw new Error(\n `HTTP ${err.response.status}: ${err.response.data?.message || 'Request failed'}`,\n )\n }\n throw new Error('Network error or request failed without a response.')\n }\n }\n\n async get(url: string, reqOptions: HTTPRequestOptions = { sendThroughProxy: true }) {\n return this.request('GET', url, undefined, reqOptions)\n }\n\n async post(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('POST', url, data, reqOptions)\n }\n\n async put(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('PUT', url, data, reqOptions)\n }\n\n async delete(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('DELETE', url, data, reqOptions)\n }\n}\n"]}
1
+ {"version":3,"file":"nvm-api.js","sourceRoot":"","sources":["../../src/api/nvm-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAA;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,yBAAyB,CAAA;AAC/D,MAAM,CAAC,MAAM,gCAAgC,GAAG,+BAA+B,CAAA;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,kCAAkC,CAAA;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,kCAAkC,CAAA;AACtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,wCAAwC,CAAA;AAC/E,iFAAiF;AACjF,8EAA8E;AAC9E,qEAAqE;AACrE,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAA;AAC3D,MAAM,CAAC,MAAM,gBAAgB,GAAG,gCAAgC,CAAA;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAA;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,uCAAuC,CAAA;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,sCAAsC,CAAA;AACxE,M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AAU,CAAC,CAAA;IACpD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,IAAS,EAAE,UAA8B;QAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IACnD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,IAAS,EAAE,UAA8B;QACjE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;IACtD,CAAC;CACF","sourcesContent":["import axios from 'axios'\n\nexport const API_URL_REGISTER_PLAN = '/api/v1/protocol/plans'\nexport const API_URL_REGISTER_AGENT = '/api/v1/protocol/agents'\nexport const API_URL_REGISTER_AGENTS_AND_PLAN = '/api/v1/protocol/agents/plans'\nexport const API_URL_GET_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_UPDATE_AGENT = '/api/v1/protocol/agents/:agentId'\nexport const API_URL_GET_AGENT_PLANS = '/api/v1/protocol/agents/:agentId/plans'\n// GET: the caller's own agents (?orgId= scopes to an org the caller belongs to).\n// Same path as API_URL_REGISTER_AGENT (disambiguated by GET vs POST); mirrors\n// the existing API_URL_REGISTER_PLAN / API_URL_GET_PLANS pair below.\nexport const API_URL_GET_AGENTS = '/api/v1/protocol/agents'\nexport const API_URL_GET_PLAN = '/api/v1/protocol/plans/:planId'\nexport const API_URL_GET_PLANS = '/api/v1/protocol/plans'\nexport const API_URL_GET_PLAN_AGENTS = '/api/v1/protocol/plans/:planId/agents'\nexport const API_URL_ORDER_PLAN = '/api/v1/protocol/plans/:planId/order'\nexport const API_URL_MINT_PLAN = '/api/v1/protocol/plans/mint'\nexport const API_URL_MINT_EXPIRABLE_PLAN = '/api/v1/protocol/plans/mintExpirable'\nexport const API_URL_ADD_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_REMOVE_PLAN_AGENT = '/api/v1/protocol/agents/:agentId/plan/:planId'\nexport const API_URL_PLAN_BALANCE = '/api/v1/protocol/plans/:planId/balance/:holderAddress'\nexport const API_URL_INITIALIZE_AGENT = '/api/v1/protocol/agents/initialize/:agentId'\nexport const API_URL_SIMULATE_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/start'\nexport const API_URL_SIMULATE_REDEEM_AGENT_REQUEST = '/api/v1/protocol/agents/simulate/finish'\nexport const API_URL_TRACK_AGENT_SUB_TASK = '/api/v1/protocol/agent-sub-tasks'\nexport const API_URL_VALIDATE_AGENT_ACCESS_TOKEN = '/api/v1/protocol/token/validate/:agentId'\nexport const API_URL_CREATE_PERMISSION = '/api/v1/x402/permissions'\nexport const API_URL_VERIFY_PERMISSIONS = '/api/v1/x402/verify'\nexport const API_URL_SETTLE_PERMISSIONS = '/api/v1/x402/settle'\n// MPP seller/buyer surface. Sibling routes of /api/v1/x402, never children:\n// an MPP access token is byte-identical to an x402 one on the wire, so the\n// route is what fixes the protocol. See nvm-monorepo#2641.\nexport const API_URL_MPP_CREATE_PERMISSION = '/api/v1/mpp/permissions'\nexport const API_URL_MPP_CHALLENGE = '/api/v1/mpp/challenge'\nexport const API_URL_MPP_VERIFY = '/api/v1/mpp/verify'\nexport const API_URL_MPP_SETTLE = '/api/v1/mpp/settle'\nexport const API_URL_STRIPE_CHECKOUT = '/api/v1/fiat/stripe/payment'\nexport const API_URL_CREATE_USER = '/api/v1/organizations/account'\nexport const API_URL_GET_MEMBERS = '/api/v1/organizations/members'\nexport const API_URL_MY_MEMBERSHIPS = '/api/v1/organizations/my-memberships'\nexport const API_URL_ORG_ACTIVITY = '/api/v1/organizations/:orgId/activity'\nexport const API_URL_CONNECT_STRIPE_ACCOUNT = '/api/v1/fiat/stripe/account'\n\nexport interface BackendApiOptions {\n /**\n * The host of the backend server\n */\n backendHost: string\n\n /**\n * The Nevermined API Key. This key identify your user and is required to interact with the Nevermined API.\n * You can get your API key by logging in to the Nevermined App.\n * @see https://nevermined.ai/docs/tutorials/integration/nvm-api-keys\n */\n apiKey?: string\n\n /**\n * The host of the Nevermined Proxy\n */\n proxyHost?: string\n\n /**\n * Additional headers to send with the requests\n */\n headers?: { [key: string]: string }\n}\n\nexport class HTTPRequestOptions {\n accessToken?: string\n sendThroughProxy = true\n proxyHost?: string = undefined\n headers?: { [key: string]: string } = {}\n}\n\nexport abstract class AbstractHTTPClient {\n // protected opts: BackendApiOptions\n // private hasKey = false\n // private agentId = ''\n\n // constructor(opts: BackendApiOptions) {\n // const defaultHeaders = {\n // Accept: 'application/json',\n // ...opts.headers,\n // ...(opts.apiKey && { Authorization: `Bearer ${opts.apiKey}` }),\n // }\n\n // this.opts = {\n // ...opts,\n // headers: defaultHeaders,\n // }\n\n // try {\n // if (this.opts.apiKey && this.opts.apiKey.length > 0) {\n // const jwt = decodeJwt(this.opts.apiKey)\n // if (isEthereumAddress(jwt.sub)) {\n // this.hasKey = true\n // }\n // }\n // } catch {\n // this.hasKey = false\n // }\n\n // let backendUrl\n // try {\n // backendUrl = new URL(this.opts.backendHost)\n // this.opts.backendHost = backendUrl.origin\n // } catch (error) {\n // throw new Error(`Invalid URL: ${this.opts.backendHost} - ${(error as Error).message}`)\n // }\n // }\n\n constructor() {\n // Empty constructor - required for abstract class implementation\n }\n\n parseUrl(urlRequested: string, reqOptions: HTTPRequestOptions) {\n let _host: URL\n if (reqOptions.sendThroughProxy) {\n if (!reqOptions.proxyHost)\n throw new Error('Proxy host is required when sendThroughProxy is true')\n return `${new URL(reqOptions.proxyHost).origin}${new URL(urlRequested).href}`\n } else {\n return urlRequested\n }\n }\n\n parseHeaders(requestHeaders: { [key: string]: string }, accessToken?: string) {\n return {\n ...(accessToken && { Authorization: `Bearer ${accessToken}` }),\n ...requestHeaders,\n }\n }\n\n // setBearerToken(token: string) {\n // this.opts.headers = {\n // ...this.opts.headers,\n // Authorization: `Bearer ${token}`,\n // }\n // }\n\n async request(\n method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',\n url: string,\n data?: any,\n reqOptions: HTTPRequestOptions = {\n sendThroughProxy: false,\n },\n ) {\n try {\n const response = await axios({\n method,\n url: this.parseUrl(url, reqOptions),\n headers: this.parseHeaders(reqOptions.headers || {}, reqOptions.accessToken),\n ...(data && { data }), // Only include `data` for methods that support it\n })\n\n return response\n } catch (err) {\n if (axios.isAxiosError(err) && err.response) {\n throw new Error(\n `HTTP ${err.response.status}: ${err.response.data?.message || 'Request failed'}`,\n )\n }\n throw new Error('Network error or request failed without a response.')\n }\n }\n\n async get(url: string, reqOptions: HTTPRequestOptions = { sendThroughProxy: true }) {\n return this.request('GET', url, undefined, reqOptions)\n }\n\n async post(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('POST', url, data, reqOptions)\n }\n\n async put(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('PUT', url, data, reqOptions)\n }\n\n async delete(url: string, data: any, reqOptions: HTTPRequestOptions) {\n return this.request('DELETE', url, data, reqOptions)\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { PaymentOptions } from '../../common/types.js';
2
2
  import { BasePaymentsAPI } from '../base-payments.js';
3
- import { CreateUserResponse, MyMembership, OrganizationActivityFilters, OrganizationActivityPage, OrganizationMemberRole, OrganizationMembersResponse, StripeCheckoutResult } from './types.js';
3
+ import { CreateUserResponse, CustomerOnboardingResponse, MyMembership, OrganizationActivityFilters, OrganizationActivityPage, OrganizationMemberRole, OrganizationMembersResponse, StripeCheckoutResult } from './types.js';
4
4
  export declare class OrganizationsAPI extends BasePaymentsAPI {
5
5
  static getInstance(options: PaymentOptions): OrganizationsAPI;
6
6
  /**
@@ -11,6 +11,24 @@ export declare class OrganizationsAPI extends BasePaymentsAPI {
11
11
  * @returns The created member
12
12
  */
13
13
  createMember(userId: string, userEmail?: string, userRole?: OrganizationMemberRole): Promise<CreateUserResponse>;
14
+ /**
15
+ * Onboard a **white-label customer** into the organization (#2418).
16
+ *
17
+ * Provisions a Nevermined account for `email` under the caller's organization
18
+ * without consuming a member seat, and returns a usable, scoped NVM API key
19
+ * the org can use to transparently act on the customer's behalf (purchase
20
+ * plans / redeem credits). The customer is recorded in the org's Customers
21
+ * list.
22
+ *
23
+ * If the email already belongs to an account the org does NOT own, no key is
24
+ * issued: an email challenge is sent to the owner and the result carries
25
+ * `consentRequired: true`. Call again once the owner has consented to complete
26
+ * onboarding.
27
+ *
28
+ * @param email - The customer's email address.
29
+ * @returns The onboarding result — either `{ nvmApiKey, userId, userWallet, isCustomer, customerRecorded }` or `{ consentRequired: true }`.
30
+ */
31
+ onboardCustomer(email: string): Promise<CustomerOnboardingResponse>;
14
32
  /**
15
33
  *
16
34
  * @param role - The role of the members to get
@@ -1 +1 @@
1
- {"version":3,"file":"organizations-api.d.ts","sourceRoot":"","sources":["../../../src/api/organizations-api/organizations-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAQrD,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,EAC3B,oBAAoB,EACrB,MAAM,YAAY,CAAA;AAEnB,qBAAa,gBAAiB,SAAQ,eAAe;IACnD,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB;IAI7D;;;;;;OAMG;IACG,YAAY,CAChB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,sBAAsB,GAChC,OAAO,CAAC,kBAAkB,CAAC;IAqB9B;;;;;;;OAOG;IACG,UAAU,CACd,IAAI,CAAC,EAAE,sBAAsB,EAC7B,QAAQ,CAAC,EAAE,OAAO,EAClB,IAAI,SAAI,EACR,MAAM,SAAM,GACX,OAAO,CAAC,2BAA2B,CAAC;IAuBvC;;;;;;;;;;;;;;;;;OAiBG;IACG,gBAAgB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAYjD;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,uBAAuB,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,wBAAwB,CAAC;IAiCpC;;;;;;;OAOG;IACG,oBAAoB,CACxB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,oBAAoB,CAAC;CAuBjC"}
1
+ {"version":3,"file":"organizations-api.d.ts","sourceRoot":"","sources":["../../../src/api/organizations-api/organizations-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAQrD,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACZ,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,EAC3B,oBAAoB,EACrB,MAAM,YAAY,CAAA;AAEnB,qBAAa,gBAAiB,SAAQ,eAAe;IACnD,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB;IAI7D;;;;;;OAMG;IACG,YAAY,CAChB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,sBAAsB,GAChC,OAAO,CAAC,kBAAkB,CAAC;IAqB9B;;;;;;;;;;;;;;;;OAgBG;IACG,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAoCzE;;;;;;;OAOG;IACG,UAAU,CACd,IAAI,CAAC,EAAE,sBAAsB,EAC7B,QAAQ,CAAC,EAAE,OAAO,EAClB,IAAI,SAAI,EACR,MAAM,SAAM,GACX,OAAO,CAAC,2BAA2B,CAAC;IAuBvC;;;;;;;;;;;;;;;;;OAiBG;IACG,gBAAgB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAYjD;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,uBAAuB,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,wBAAwB,CAAC;IAiCpC;;;;;;;OAOG;IACG,oBAAoB,CACxB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,oBAAoB,CAAC;CAuBjC"}
@@ -31,6 +31,55 @@ export class OrganizationsAPI extends BasePaymentsAPI {
31
31
  nvmApiKey: data.walletResult.hash,
32
32
  };
33
33
  }
34
+ /**
35
+ * Onboard a **white-label customer** into the organization (#2418).
36
+ *
37
+ * Provisions a Nevermined account for `email` under the caller's organization
38
+ * without consuming a member seat, and returns a usable, scoped NVM API key
39
+ * the org can use to transparently act on the customer's behalf (purchase
40
+ * plans / redeem credits). The customer is recorded in the org's Customers
41
+ * list.
42
+ *
43
+ * If the email already belongs to an account the org does NOT own, no key is
44
+ * issued: an email challenge is sent to the owner and the result carries
45
+ * `consentRequired: true`. Call again once the owner has consented to complete
46
+ * onboarding.
47
+ *
48
+ * @param email - The customer's email address.
49
+ * @returns The onboarding result — either `{ nvmApiKey, userId, userWallet, isCustomer, customerRecorded }` or `{ consentRequired: true }`.
50
+ */
51
+ async onboardCustomer(email) {
52
+ const body = { email, as: 'customer' };
53
+ const options = this.getBackendHTTPOptions('POST', body);
54
+ const url = new URL(API_URL_CREATE_USER, this.environment.backend);
55
+ const response = await fetch(url, options);
56
+ if (!response.ok) {
57
+ const error = await response.json().catch(() => ({ message: 'Unknown error' }));
58
+ throw PaymentsError.fromBackend('Unable to onboard customer', error);
59
+ }
60
+ const wallet = (await response.json())?.walletResult ?? {};
61
+ // Existing, non-owned account: opaque consent-pending outcome. The backend
62
+ // signals it with HTTP 202 and `walletResult.consentRequired`; treat either
63
+ // as authoritative so a body-parsing quirk can't slip through as "success".
64
+ // No identity or key is disclosed.
65
+ if (response.status === 202 || wallet.consentRequired) {
66
+ return { consentRequired: true };
67
+ }
68
+ // New account or the org's returning customer: a usable key MUST be present.
69
+ // A 2xx without one means a partial/unexpected payload — fail loudly rather
70
+ // than hand back a "success" carrying undefined credentials.
71
+ if (!wallet.nvmApiKey) {
72
+ throw PaymentsError.internal('Customer onboarding did not return an API key (unexpected backend response)');
73
+ }
74
+ return {
75
+ consentRequired: false,
76
+ nvmApiKey: wallet.nvmApiKey,
77
+ userId: wallet.userId,
78
+ userWallet: wallet.userWallet,
79
+ isCustomer: wallet.isCustomer,
80
+ customerRecorded: wallet.customerRecorded,
81
+ };
82
+ }
34
83
  /**
35
84
  *
36
85
  * @param role - The role of the members to get
@@ -1 +1 @@
1
- {"version":3,"file":"organizations-api.js","sourceRoot":"","sources":["../../../src/api/organizations-api/organizations-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EACL,8BAA8B,EAC9B,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,eAAe,CAAA;AAWtB,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IACnD,MAAM,CAAC,WAAW,CAAC,OAAuB;QACxC,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACtC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAChB,MAAc,EACd,SAAkB,EAClB,QAAiC;QAEjC,MAAM,IAAI,GAAG;YACX,gBAAgB,EAAE,MAAM;YACxB,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,QAAQ;SACf,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACxD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC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CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC,CAAA;YAC/E,MAAM,aAAa,CAAC,WAAW,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAA;QACzE,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClC,OAAO;YACL,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAA;IACH,CAAC;CACF","sourcesContent":["import { PaymentsError } from '../../common/payments.error.js'\nimport { PaymentOptions } from '../../common/types.js'\nimport { BasePaymentsAPI } from '../base-payments.js'\nimport {\n API_URL_CONNECT_STRIPE_ACCOUNT,\n API_URL_CREATE_USER,\n API_URL_GET_MEMBERS,\n API_URL_MY_MEMBERSHIPS,\n API_URL_ORG_ACTIVITY,\n} from '../nvm-api.js'\nimport {\n CreateUserResponse,\n MyMembership,\n OrganizationActivityFilters,\n OrganizationActivityPage,\n OrganizationMemberRole,\n OrganizationMembersResponse,\n StripeCheckoutResult,\n} from './types.js'\n\nexport class OrganizationsAPI extends BasePaymentsAPI {\n static getInstance(options: PaymentOptions): OrganizationsAPI {\n return new OrganizationsAPI(options)\n }\n\n /**\n * Create a new member in the organization\n * @param userId - The unique external ID of the new member\n * @param userEmail - The email of the new member\n * @param userRole - The role of the new member\n * @returns The created member\n */\n async createMember(\n userId: string,\n userEmail?: string,\n userRole?: OrganizationMemberRole,\n ): Promise<CreateUserResponse> {\n const body = {\n uniqueExternalId: userId,\n email: userEmail,\n role: userRole,\n }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_CREATE_USER, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to create user', error)\n }\n\n const data = await response.json()\n return {\n ...data.walletResult,\n nvmApiKey: data.walletResult.hash,\n }\n }\n\n /**\n *\n * @param role - The role of the members to get\n * @param isActive - The active status of the members to get\n * @param page - The page of the members to get\n * @param offset - The number of members to get per page\n * @returns The list of members\n */\n async getMembers(\n role?: OrganizationMemberRole,\n isActive?: boolean,\n page = 1,\n offset = 100,\n ): Promise<OrganizationMembersResponse> {\n const body = {\n role,\n isActive,\n page,\n offset,\n }\n const url = new URL(API_URL_GET_MEMBERS, this.environment.backend)\n const options = this.getBackendHTTPOptions('POST', body)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to get members', error)\n }\n\n const data = await response.json()\n return {\n members: data.members,\n total: data.totalResults,\n }\n }\n\n /**\n * Lists every organization the authenticated user is an active member of,\n * with their role and the organization's tier.\n *\n * Powers workspace pickers in third-party tools built on the SDK, and the\n * \"where will this publish?\" UX when a user belongs to multiple orgs.\n *\n * @returns An array of {@link MyMembership} — empty when the user has no\n * active memberships and operates as a personal account.\n *\n * @example\n * ```ts\n * const memberships = await payments.organizations.getMyMemberships()\n * for (const m of memberships) {\n * console.log(`${m.orgName} — ${m.role}`)\n * }\n * ```\n */\n async getMyMemberships(): Promise<MyMembership[]> {\n const url = new URL(API_URL_MY_MEMBERSHIPS, this.environment.backend)\n const options = this.getBackendHTTPOptions('GET')\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to fetch memberships', error)\n }\n const data = (await response.json()) as MyMembership[]\n return Array.isArray(data) ? data : []\n }\n\n /**\n * Lists events emitted into the activity feed of an organization the\n * caller is an active member of (member invites, customer events,\n * subscription transitions, webhook deliveries, …).\n *\n * Requires the caller to be a Member or Admin of `orgId`; the backend\n * returns 403 otherwise. Premium+ entitlement is enforced server-side.\n *\n * @param orgId - The organization id (e.g. `org-…`) whose feed to read.\n * @param filters - Optional filter set — see {@link OrganizationActivityFilters}.\n * @returns A paginated {@link OrganizationActivityPage}.\n *\n * @example\n * ```ts\n * const page = await payments.organizations.getOrganizationActivity(orgId, {\n * eventType: OrganizationActivityEventType.MemberInvited,\n * page: 1,\n * limit: 25,\n * })\n * ```\n */\n async getOrganizationActivity(\n orgId: string,\n filters: OrganizationActivityFilters = {},\n ): Promise<OrganizationActivityPage> {\n if (!orgId) {\n throw new PaymentsError('orgId is required')\n }\n const params = new URLSearchParams()\n if (filters.eventType !== undefined) {\n const eventType = Array.isArray(filters.eventType)\n ? filters.eventType.map(String).join(',')\n : String(filters.eventType)\n if (eventType.length > 0) params.set('eventType', eventType)\n }\n if (filters.actorUserId) params.set('actorUserId', filters.actorUserId)\n if (filters.from) params.set('from', filters.from)\n if (filters.to) params.set('to', filters.to)\n if (filters.page !== undefined) params.set('page', String(filters.page))\n if (filters.limit !== undefined) params.set('limit', String(filters.limit))\n\n const path = API_URL_ORG_ACTIVITY.replace(':orgId', encodeURIComponent(orgId))\n const queryString = params.toString()\n const url = new URL(queryString ? `${path}?${queryString}` : path, this.environment.backend)\n const options = this.getBackendHTTPOptions('GET')\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to fetch organization activity', error)\n }\n const data = (await response.json()) as Partial<OrganizationActivityPage>\n return {\n items: Array.isArray(data.items) ? data.items : [],\n total: typeof data.total === 'number' ? data.total : 0,\n }\n }\n\n /**\n * Connect user with Stripe\n * @param userEmail - The email of the user\n * @param userCountryCode - The country code of the user\n * @param returnUrl - The return URL after the Stripe connection is completed\n * @returns The Stripe checkout result including the stripe account link, stripe account id, user id, user country code, link created at and link expires at.\n * The stripe account link is the link that the user needs to click to connect with Stripe.\n */\n async connectStripeAccount(\n userEmail: string,\n userCountryCode: string,\n returnUrl: string,\n ): Promise<StripeCheckoutResult> {\n const body = {\n userEmail,\n userCountryCode,\n returnUrl,\n }\n const url = new URL(API_URL_CONNECT_STRIPE_ACCOUNT, this.environment.backend)\n const options = this.getBackendHTTPOptions('POST', body)\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to connect with Stripe', error)\n }\n const data = await response.json()\n return {\n stripeAccountLink: data.stripeAccountLink,\n stripeAccountId: data.stripeAccountId,\n userId: data.userId,\n userCountryCode: data.userCountryCode,\n linkCreatedAt: data.linkCreatedAt,\n linkExpiresAt: data.linkExpiresAt,\n }\n }\n}\n"]}
1
+ {"version":3,"file":"organizations-api.js","sourceRoot":"","sources":["../../../src/api/organizations-api/organizations-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EACL,8BAA8B,EAC9B,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,eAAe,CAAA;AAYtB,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IACnD,MAAM,CAAC,WAAW,CAAC,OAAuB;QACxC,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACtC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAChB,MAAc,EACd,SAAkB,EAClB,QAAiC;QAEjC,MAAM,IAAI,GAAG;YACX,gBAAgB,EAAE,MAAM;YACxB,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,QAAQ;SACf,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACx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8B,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAC7E,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACxD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC,CAAA;YAC/E,MAAM,aAAa,CAAC,WAAW,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAA;QACzE,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClC,OAAO;YACL,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAA;IACH,CAAC;CACF","sourcesContent":["import { PaymentsError } from '../../common/payments.error.js'\nimport { PaymentOptions } from '../../common/types.js'\nimport { BasePaymentsAPI } from '../base-payments.js'\nimport {\n API_URL_CONNECT_STRIPE_ACCOUNT,\n API_URL_CREATE_USER,\n API_URL_GET_MEMBERS,\n API_URL_MY_MEMBERSHIPS,\n API_URL_ORG_ACTIVITY,\n} from '../nvm-api.js'\nimport {\n CreateUserResponse,\n CustomerOnboardingResponse,\n MyMembership,\n OrganizationActivityFilters,\n OrganizationActivityPage,\n OrganizationMemberRole,\n OrganizationMembersResponse,\n StripeCheckoutResult,\n} from './types.js'\n\nexport class OrganizationsAPI extends BasePaymentsAPI {\n static getInstance(options: PaymentOptions): OrganizationsAPI {\n return new OrganizationsAPI(options)\n }\n\n /**\n * Create a new member in the organization\n * @param userId - The unique external ID of the new member\n * @param userEmail - The email of the new member\n * @param userRole - The role of the new member\n * @returns The created member\n */\n async createMember(\n userId: string,\n userEmail?: string,\n userRole?: OrganizationMemberRole,\n ): Promise<CreateUserResponse> {\n const body = {\n uniqueExternalId: userId,\n email: userEmail,\n role: userRole,\n }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_CREATE_USER, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to create user', error)\n }\n\n const data = await response.json()\n return {\n ...data.walletResult,\n nvmApiKey: data.walletResult.hash,\n }\n }\n\n /**\n * Onboard a **white-label customer** into the organization (#2418).\n *\n * Provisions a Nevermined account for `email` under the caller's organization\n * without consuming a member seat, and returns a usable, scoped NVM API key\n * the org can use to transparently act on the customer's behalf (purchase\n * plans / redeem credits). The customer is recorded in the org's Customers\n * list.\n *\n * If the email already belongs to an account the org does NOT own, no key is\n * issued: an email challenge is sent to the owner and the result carries\n * `consentRequired: true`. Call again once the owner has consented to complete\n * onboarding.\n *\n * @param email - The customer's email address.\n * @returns The onboarding result — either `{ nvmApiKey, userId, userWallet, isCustomer, customerRecorded }` or `{ consentRequired: true }`.\n */\n async onboardCustomer(email: string): Promise<CustomerOnboardingResponse> {\n const body = { email, as: 'customer' }\n const options = this.getBackendHTTPOptions('POST', body)\n const url = new URL(API_URL_CREATE_USER, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to onboard customer', error)\n }\n\n const wallet = (await response.json())?.walletResult ?? {}\n // Existing, non-owned account: opaque consent-pending outcome. The backend\n // signals it with HTTP 202 and `walletResult.consentRequired`; treat either\n // as authoritative so a body-parsing quirk can't slip through as \"success\".\n // No identity or key is disclosed.\n if (response.status === 202 || wallet.consentRequired) {\n return { consentRequired: true }\n }\n // New account or the org's returning customer: a usable key MUST be present.\n // A 2xx without one means a partial/unexpected payload — fail loudly rather\n // than hand back a \"success\" carrying undefined credentials.\n if (!wallet.nvmApiKey) {\n throw PaymentsError.internal(\n 'Customer onboarding did not return an API key (unexpected backend response)',\n )\n }\n return {\n consentRequired: false,\n nvmApiKey: wallet.nvmApiKey,\n userId: wallet.userId,\n userWallet: wallet.userWallet,\n isCustomer: wallet.isCustomer,\n customerRecorded: wallet.customerRecorded,\n }\n }\n\n /**\n *\n * @param role - The role of the members to get\n * @param isActive - The active status of the members to get\n * @param page - The page of the members to get\n * @param offset - The number of members to get per page\n * @returns The list of members\n */\n async getMembers(\n role?: OrganizationMemberRole,\n isActive?: boolean,\n page = 1,\n offset = 100,\n ): Promise<OrganizationMembersResponse> {\n const body = {\n role,\n isActive,\n page,\n offset,\n }\n const url = new URL(API_URL_GET_MEMBERS, this.environment.backend)\n const options = this.getBackendHTTPOptions('POST', body)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to get members', error)\n }\n\n const data = await response.json()\n return {\n members: data.members,\n total: data.totalResults,\n }\n }\n\n /**\n * Lists every organization the authenticated user is an active member of,\n * with their role and the organization's tier.\n *\n * Powers workspace pickers in third-party tools built on the SDK, and the\n * \"where will this publish?\" UX when a user belongs to multiple orgs.\n *\n * @returns An array of {@link MyMembership} — empty when the user has no\n * active memberships and operates as a personal account.\n *\n * @example\n * ```ts\n * const memberships = await payments.organizations.getMyMemberships()\n * for (const m of memberships) {\n * console.log(`${m.orgName} — ${m.role}`)\n * }\n * ```\n */\n async getMyMemberships(): Promise<MyMembership[]> {\n const url = new URL(API_URL_MY_MEMBERSHIPS, this.environment.backend)\n const options = this.getBackendHTTPOptions('GET')\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to fetch memberships', error)\n }\n const data = (await response.json()) as MyMembership[]\n return Array.isArray(data) ? data : []\n }\n\n /**\n * Lists events emitted into the activity feed of an organization the\n * caller is an active member of (member invites, customer events,\n * subscription transitions, webhook deliveries, …).\n *\n * Requires the caller to be a Member or Admin of `orgId`; the backend\n * returns 403 otherwise. Premium+ entitlement is enforced server-side.\n *\n * @param orgId - The organization id (e.g. `org-…`) whose feed to read.\n * @param filters - Optional filter set — see {@link OrganizationActivityFilters}.\n * @returns A paginated {@link OrganizationActivityPage}.\n *\n * @example\n * ```ts\n * const page = await payments.organizations.getOrganizationActivity(orgId, {\n * eventType: OrganizationActivityEventType.MemberInvited,\n * page: 1,\n * limit: 25,\n * })\n * ```\n */\n async getOrganizationActivity(\n orgId: string,\n filters: OrganizationActivityFilters = {},\n ): Promise<OrganizationActivityPage> {\n if (!orgId) {\n throw new PaymentsError('orgId is required')\n }\n const params = new URLSearchParams()\n if (filters.eventType !== undefined) {\n const eventType = Array.isArray(filters.eventType)\n ? filters.eventType.map(String).join(',')\n : String(filters.eventType)\n if (eventType.length > 0) params.set('eventType', eventType)\n }\n if (filters.actorUserId) params.set('actorUserId', filters.actorUserId)\n if (filters.from) params.set('from', filters.from)\n if (filters.to) params.set('to', filters.to)\n if (filters.page !== undefined) params.set('page', String(filters.page))\n if (filters.limit !== undefined) params.set('limit', String(filters.limit))\n\n const path = API_URL_ORG_ACTIVITY.replace(':orgId', encodeURIComponent(orgId))\n const queryString = params.toString()\n const url = new URL(queryString ? `${path}?${queryString}` : path, this.environment.backend)\n const options = this.getBackendHTTPOptions('GET')\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to fetch organization activity', error)\n }\n const data = (await response.json()) as Partial<OrganizationActivityPage>\n return {\n items: Array.isArray(data.items) ? data.items : [],\n total: typeof data.total === 'number' ? data.total : 0,\n }\n }\n\n /**\n * Connect user with Stripe\n * @param userEmail - The email of the user\n * @param userCountryCode - The country code of the user\n * @param returnUrl - The return URL after the Stripe connection is completed\n * @returns The Stripe checkout result including the stripe account link, stripe account id, user id, user country code, link created at and link expires at.\n * The stripe account link is the link that the user needs to click to connect with Stripe.\n */\n async connectStripeAccount(\n userEmail: string,\n userCountryCode: string,\n returnUrl: string,\n ): Promise<StripeCheckoutResult> {\n const body = {\n userEmail,\n userCountryCode,\n returnUrl,\n }\n const url = new URL(API_URL_CONNECT_STRIPE_ACCOUNT, this.environment.backend)\n const options = this.getBackendHTTPOptions('POST', body)\n const response = await fetch(url, options)\n if (!response.ok) {\n const error = await response.json().catch(() => ({ message: 'Unknown error' }))\n throw PaymentsError.fromBackend('Unable to connect with Stripe', error)\n }\n const data = await response.json()\n return {\n stripeAccountLink: data.stripeAccountLink,\n stripeAccountId: data.stripeAccountId,\n userId: data.userId,\n userCountryCode: data.userCountryCode,\n linkCreatedAt: data.linkCreatedAt,\n linkExpiresAt: data.linkExpiresAt,\n }\n }\n}\n"]}
@@ -26,6 +26,33 @@ export type CreateUserResponse = {
26
26
  userWallet: string;
27
27
  alreadyMember: boolean;
28
28
  };
29
+ /**
30
+ * Result of onboarding a white-label customer via
31
+ * `POST /organizations/account` with `as: 'customer'` (nvm-monorepo #2418).
32
+ *
33
+ * A discriminated union on `consentRequired` — narrow on it to get the right
34
+ * shape with no impossible states:
35
+ * - `{ consentRequired: true }` — the email belongs to an account the org does
36
+ * NOT own. NO key is issued (HTTP 202); an email challenge was sent to the
37
+ * owner and the account's identity is deliberately withheld. Retry once they
38
+ * consent.
39
+ * - `{ consentRequired: false, nvmApiKey, ... }` — a new account or the org's
40
+ * returning customer. A usable, scoped `nvmApiKey` is always present and the
41
+ * customer is recorded in the org's Customers list.
42
+ */
43
+ export type CustomerOnboardingResponse = {
44
+ consentRequired: true;
45
+ } | {
46
+ consentRequired: false;
47
+ /** The usable NVM API key (Bearer credential). Always present in this branch. */
48
+ nvmApiKey: string;
49
+ userId: string;
50
+ userWallet: string;
51
+ /** True when a key was issued for a customer (new account or renewal). */
52
+ isCustomer: boolean;
53
+ /** Whether the customer was written to the org's Customers list (best-effort). */
54
+ customerRecorded: boolean;
55
+ };
29
56
  /**
30
57
  * A single organization the authenticated user is an active member of.
31
58
  * Returned by `OrganizationsAPI.getMyMemberships()` and used by clients to
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/api/organizations-api/types.ts"],"names":[],"mappings":"AAAA,oBAAY,sBAAsB;IAChC,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED;;;;;;;;;;GAUG;AACH,oBAAY,gBAAgB;IAC1B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,OAAO,CAAA;CACvB,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAA;IACb,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAA;IACf,8CAA8C;IAC9C,IAAI,EAAE,sBAAsB,CAAA;IAC5B,+DAA+D;IAC/D,OAAO,EAAE,gBAAgB,CAAA;IACzB,2DAA2D;IAC3D,OAAO,EAAE,OAAO,CAAA;IAChB;;;;;;OAMG;IACH,sBAAsB,EAAE,OAAO,CAAA;CAChC,CAAA;AAED;;;;;GAKG;AACH,oBAAY,6BAA6B;IAEvC,aAAa,mBAAmB;IAChC,YAAY,kBAAkB;IAC9B,iBAAiB,wBAAwB;IACzC,iBAAiB,uBAAuB;IACxC,iBAAiB,uBAAuB;IACxC,aAAa,mBAAmB;IAChC,iBAAiB,uBAAuB;IACxC,iBAAiB,uBAAuB;IAExC,YA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AAE,CAAC,EAAE,MAAM,CAAA;IACX,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,sBAAsB,CAAA;IAC5B,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,OAAO,EAAE,kBAAkB,EAAE,CAAA;IAC7B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,EAAE,MAAM,CAAA;IACvB,iBAAiB,EAAE,MAAM,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/api/organizations-api/types.ts"],"names":[],"mappings":"AAAA,oBAAY,sBAAsB;IAChC,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED;;;;;;;;;;GAUG;AACH,oBAAY,gBAAgB;IAC1B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,OAAO,CAAA;CACvB,CAAA;AAED;;;;;;;;;;;;;GAaG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AAI,EAAE,sBAAsB,CAAA;IAC5B,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,OAAO,EAAE,kBAAkB,EAAE,CAAA;IAC7B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,EAAE,MAAM,CAAA;IACvB,iBAAiB,EAAE,MAAM,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/api/organizations-api/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,sBAIX;AAJD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,2CAAiB,CAAA;IACjB,2CAAiB,CAAA;AACnB,CAAC,EAJW,sBAAsB,KAAtB,sBAAsB,QAIjC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,uCAAmB,CAAA;IACnB,6CAAyB,CAAA;IACzB,qCAAiB,CAAA;IACjB,mCAAe,CAAA;AACjB,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B;AAsCD;;;;;GAKG;AACH,MAAM,CAAN,IAAY,6BA0BX;AA1BD,WAAY,6BAA6B;IACvC,uBAAuB;IACvB,iEAAgC,CAAA;IAChC,+DAA8B,CAAA;IAC9B,0EAAyC,CAAA;IACzC,yEAAwC,CAAA;IACxC,yEAAwC,CAAA;IACxC,iEAAgC,CAAA;IAChC,yEAAwC,CAAA;IACxC,yEAAwC,CAAA;IACxC,qBAAqB;IACrB,+DAA8B,CAAA;IAC9B,6DAA4B,CAAA;IAC5B,iEAAgC,CAAA;IAChC,qBAAqB;IACrB,iEAAgC,CAAA;IAChC,qEAAoC,CAAA;IACpC,yEAAwC,CAAA;IACxC,yBAAyB;IACzB,+EAA8C,CAAA;IAC9C,mFAAkD,CAAA;IAClD,+EAA8C,CAAA;IAC9C,2EAA0C,CAAA;IAC1C,mBAAmB;IACnB,uEAAsC,CAAA;IACtC,iEAAgC,CAAA;AAClC,CAAC,EA1BW,6BAA6B,KAA7B,6BAA6B,QA0BxC","sourcesContent":["export enum OrganizationMemberRole {\n Admin = 'Admin',\n Member = 'Member',\n Client = 'Client',\n}\n\n/**\n * Tier of an organization. Mirrors the backend `OrganizationType` enum at\n * `libs/commons/src/lib/types/types.ts` in nvm-monorepo.\n *\n * - `Premium` / `Enterprise` — the paid tiers from Epic #1339.\n * - `Lapsed` — an org whose paid subscription has expired; replaces the\n * retired `Free` bucket (the backend never emits `Free` for new rows).\n * - `Other` — legacy pre-tiered-pricing bucket still returned for orgs that\n * pre-date the tier system; inherits Premium-equivalent caps and features\n * server-side.\n */\nexport enum OrganizationType {\n Premium = 'Premium',\n Enterprise = 'Enterprise',\n Lapsed = 'Lapsed',\n Other = 'Other',\n}\n\nexport type CreateUserResponse = {\n nvmApiKey: string\n userId: string\n userWallet: string\n alreadyMember: boolean\n}\n\n/**\n * A single organization the authenticated user is an active member of.\n * Returned by `OrganizationsAPI.getMyMemberships()` and used by clients to\n * power workspace pickers and \"where will this publish?\" UX.\n *\n * Shape mirrors `MyMembershipDto` in the Nevermined backend\n * (`apps/api/src/organizations/dto/my-membership.dto.ts`).\n */\nexport type MyMembership = {\n /** Stable organization id (e.g. `org-…`). */\n orgId: string\n /** Display name of the organization. */\n orgName: string\n /** Caller's role inside this organization. */\n role: OrganizationMemberRole\n /** Tier of the organization — see {@link OrganizationType}. */\n orgType: OrganizationType\n /** Whether the caller is an Admin of this organization. */\n isAdmin: boolean\n /**\n * `true` when the org has at least one `organizationSubscription` row —\n * the org has previously been associated with a paid tier (active,\n * past_due, trialing, lapsed, or canceled). Combined with\n * `orgType === Lapsed` it distinguishes \"subscription expired\" from\n * \"free org that never subscribed\".\n */\n hasSubscriptionHistory: boolean\n}\n\n/**\n * Event types emitted into the organization activity feed. Values mirror\n * the backend enum in `@nevermined-io/commons`. Stored on the wire as\n * dot-namespaced lowercase strings — the SDK accepts any string for\n * forward-compatibility when new event types are introduced server-side.\n */\nexport enum OrganizationActivityEventType {\n // Membership lifecycle\n MemberInvited = 'member.invited',\n MemberJoined = 'member.joined',\n MemberRoleChanged = 'member.role_changed',\n MemberDeactivated = 'member.deactivated',\n MemberReactivated = 'member.reactivated',\n MemberRemoved = 'member.removed',\n InvitationRevoked = 'invitation.revoked',\n InvitationExpired = 'invitation.expired',\n // Resource lifecycle\n AgentCreated = 'agent.created',\n PlanCreated = 'plan.created',\n PlanPurchased = 'plan.purchased',\n // Customer lifecycle\n CustomerAdded = 'customer.added',\n CustomerBlocked = 'customer.blocked',\n CustomerUnblocked = 'customer.unblocked',\n // Subscription lifecycle\n SubscriptionUpgraded = 'subscription.upgraded',\n SubscriptionDowngraded = 'subscription.downgraded',\n SubscriptionCanceled = 'subscription.canceled',\n SubscriptionLapsed = 'subscription.lapsed',\n // Webhook delivery\n WebhookDelivered = 'webhook.delivered',\n WebhookFailed = 'webhook.failed',\n}\n\n/**\n * The resource an activity event is about. `kind` describes the resource\n * type (`plan`, `agent`, `member`, `subscription`, `invitation`, `customer`,\n * `webhook`) and `id` is the resource's identifier. Extras vary by kind —\n * e.g. invitations include `role` + `email`, members include `role` +\n * `userId`, subscriptions include `tier`.\n */\nexport type OrganizationActivityEventSubject = {\n kind: string\n id: string\n [key: string]: unknown\n}\n\n/**\n * A single event emitted into the organization activity feed. Shape mirrors\n * `OrganizationActivityEventResponseDto` in the Nevermined backend.\n */\nexport type OrganizationActivityEvent = {\n /** Activity event ID (e.g. `ae-{uuid}`). */\n id: string\n /**\n * Backend-emitted event type. Use {@link OrganizationActivityEventType}\n * for known values; the field stays a plain string so a new server-side\n * event type doesn't break consumers.\n */\n eventType: OrganizationActivityEventType | string\n /** User who triggered the event, or `null` for system-emitted events. */\n actorUserId: string | null\n /** Resource the event is about — see {@link OrganizationActivityEventSubject}. */\n subject: OrganizationActivityEventSubject\n /** Optional payload (e.g. previous/current values on role/status changes). */\n metadata: Record<string, unknown> | null\n /** ISO-8601 timestamp of when the event occurred. */\n occurredAt: string\n}\n\n/**\n * Paginated page of activity events. The backend only echoes `items` and\n * `total`; `page` / `limit` are not in the response — they're the values\n * the caller asked for in {@link OrganizationActivityFilters}.\n */\nexport type OrganizationActivityPage = {\n items: OrganizationActivityEvent[]\n total: number\n}\n\n/** Filters accepted by `OrganizationsAPI.getOrganizationActivity`. */\nexport type OrganizationActivityFilters = {\n /**\n * Restrict to one or more event types. Accepts a single string, an enum\n * value, or an array (sent to the backend as a comma-separated list).\n */\n eventType?: OrganizationActivityEventType | string | Array<OrganizationActivityEventType | string>\n /** Restrict to events triggered by a specific user. */\n actorUserId?: string\n /** ISO-8601 lower bound (inclusive) on `occurredAt`. */\n from?: string\n /** ISO-8601 upper bound (exclusive) on `occurredAt`. */\n to?: string\n /** Page number — 1-based. */\n page?: number\n /** Page size — backend cap is 200. */\n limit?: number\n}\n\nexport type OrganizationMember = {\n createdAt: string\n updatedAt: string\n id: string\n userId: string\n orgId: string\n userAddress: string\n role: OrganizationMemberRole\n isActive: boolean\n}\n\nexport type OrganizationMembersResponse = {\n members: OrganizationMember[]\n total: number\n}\n\nexport type StripeCheckoutResult = {\n stripeAccountId: string\n stripeAccountLink: string\n userId: string\n userCountryCode: string\n linkCreatedAt: number\n linkExpiresAt: number\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/api/organizations-api/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,sBAIX;AAJD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,2CAAiB,CAAA;IACjB,2CAAiB,CAAA;AACnB,CAAC,EAJW,sBAAsB,KAAtB,sBAAsB,QAIjC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,uCAAmB,CAAA;IACnB,6CAAyB,CAAA;IACzB,qCAAiB,CAAA;IACjB,mCAAe,CAAA;AACjB,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B;AAkED;;;;;GAKG;AACH,MAAM,CAAN,IAAY,6BA0BX;AA1BD,WAAY,6BAA6B;IACvC,uBAAuB;IACvB,iEAAgC,CAAA;IAChC,+DAA8B,CAAA;IAC9B,0EAAyC,CAAA;IACzC,yEAAwC,CAAA;IACxC,yEAAwC,CAAA;IACxC,iEAAgC,CAAA;IAChC,yEAAwC,CAAA;IACxC,yEAAwC,CAAA;IACxC,qBAAqB;IACrB,+DAA8B,CAAA;IAC9B,6DAA4B,CAAA;IAC5B,iEAAgC,CAAA;IAChC,qBAAqB;IACrB,iEAAgC,CAAA;IAChC,qEAAoC,CAAA;IACpC,yEAAwC,CAAA;IACxC,yBAAyB;IACzB,+EAA8C,CAAA;IAC9C,mFAAkD,CAAA;IAClD,+EAA8C,CAAA;IAC9C,2EAA0C,CAAA;IAC1C,mBAAmB;IACnB,uEAAsC,CAAA;IACtC,iEAAgC,CAAA;AAClC,CAAC,EA1BW,6BAA6B,KAA7B,6BAA6B,QA0BxC","sourcesContent":["export enum OrganizationMemberRole {\n Admin = 'Admin',\n Member = 'Member',\n Client = 'Client',\n}\n\n/**\n * Tier of an organization. Mirrors the backend `OrganizationType` enum at\n * `libs/commons/src/lib/types/types.ts` in nvm-monorepo.\n *\n * - `Premium` / `Enterprise` — the paid tiers from Epic #1339.\n * - `Lapsed` — an org whose paid subscription has expired; replaces the\n * retired `Free` bucket (the backend never emits `Free` for new rows).\n * - `Other` — legacy pre-tiered-pricing bucket still returned for orgs that\n * pre-date the tier system; inherits Premium-equivalent caps and features\n * server-side.\n */\nexport enum OrganizationType {\n Premium = 'Premium',\n Enterprise = 'Enterprise',\n Lapsed = 'Lapsed',\n Other = 'Other',\n}\n\nexport type CreateUserResponse = {\n nvmApiKey: string\n userId: string\n userWallet: string\n alreadyMember: boolean\n}\n\n/**\n * Result of onboarding a white-label customer via\n * `POST /organizations/account` with `as: 'customer'` (nvm-monorepo #2418).\n *\n * A discriminated union on `consentRequired` — narrow on it to get the right\n * shape with no impossible states:\n * - `{ consentRequired: true }` — the email belongs to an account the org does\n * NOT own. NO key is issued (HTTP 202); an email challenge was sent to the\n * owner and the account's identity is deliberately withheld. Retry once they\n * consent.\n * - `{ consentRequired: false, nvmApiKey, ... }` — a new account or the org's\n * returning customer. A usable, scoped `nvmApiKey` is always present and the\n * customer is recorded in the org's Customers list.\n */\nexport type CustomerOnboardingResponse =\n | { consentRequired: true }\n | {\n consentRequired: false\n /** The usable NVM API key (Bearer credential). Always present in this branch. */\n nvmApiKey: string\n userId: string\n userWallet: string\n /** True when a key was issued for a customer (new account or renewal). */\n isCustomer: boolean\n /** Whether the customer was written to the org's Customers list (best-effort). */\n customerRecorded: boolean\n }\n\n/**\n * A single organization the authenticated user is an active member of.\n * Returned by `OrganizationsAPI.getMyMemberships()` and used by clients to\n * power workspace pickers and \"where will this publish?\" UX.\n *\n * Shape mirrors `MyMembershipDto` in the Nevermined backend\n * (`apps/api/src/organizations/dto/my-membership.dto.ts`).\n */\nexport type MyMembership = {\n /** Stable organization id (e.g. `org-…`). */\n orgId: string\n /** Display name of the organization. */\n orgName: string\n /** Caller's role inside this organization. */\n role: OrganizationMemberRole\n /** Tier of the organization — see {@link OrganizationType}. */\n orgType: OrganizationType\n /** Whether the caller is an Admin of this organization. */\n isAdmin: boolean\n /**\n * `true` when the org has at least one `organizationSubscription` row —\n * the org has previously been associated with a paid tier (active,\n * past_due, trialing, lapsed, or canceled). Combined with\n * `orgType === Lapsed` it distinguishes \"subscription expired\" from\n * \"free org that never subscribed\".\n */\n hasSubscriptionHistory: boolean\n}\n\n/**\n * Event types emitted into the organization activity feed. Values mirror\n * the backend enum in `@nevermined-io/commons`. Stored on the wire as\n * dot-namespaced lowercase strings — the SDK accepts any string for\n * forward-compatibility when new event types are introduced server-side.\n */\nexport enum OrganizationActivityEventType {\n // Membership lifecycle\n MemberInvited = 'member.invited',\n MemberJoined = 'member.joined',\n MemberRoleChanged = 'member.role_changed',\n MemberDeactivated = 'member.deactivated',\n MemberReactivated = 'member.reactivated',\n MemberRemoved = 'member.removed',\n InvitationRevoked = 'invitation.revoked',\n InvitationExpired = 'invitation.expired',\n // Resource lifecycle\n AgentCreated = 'agent.created',\n PlanCreated = 'plan.created',\n PlanPurchased = 'plan.purchased',\n // Customer lifecycle\n CustomerAdded = 'customer.added',\n CustomerBlocked = 'customer.blocked',\n CustomerUnblocked = 'customer.unblocked',\n // Subscription lifecycle\n SubscriptionUpgraded = 'subscription.upgraded',\n SubscriptionDowngraded = 'subscription.downgraded',\n SubscriptionCanceled = 'subscription.canceled',\n SubscriptionLapsed = 'subscription.lapsed',\n // Webhook delivery\n WebhookDelivered = 'webhook.delivered',\n WebhookFailed = 'webhook.failed',\n}\n\n/**\n * The resource an activity event is about. `kind` describes the resource\n * type (`plan`, `agent`, `member`, `subscription`, `invitation`, `customer`,\n * `webhook`) and `id` is the resource's identifier. Extras vary by kind —\n * e.g. invitations include `role` + `email`, members include `role` +\n * `userId`, subscriptions include `tier`.\n */\nexport type OrganizationActivityEventSubject = {\n kind: string\n id: string\n [key: string]: unknown\n}\n\n/**\n * A single event emitted into the organization activity feed. Shape mirrors\n * `OrganizationActivityEventResponseDto` in the Nevermined backend.\n */\nexport type OrganizationActivityEvent = {\n /** Activity event ID (e.g. `ae-{uuid}`). */\n id: string\n /**\n * Backend-emitted event type. Use {@link OrganizationActivityEventType}\n * for known values; the field stays a plain string so a new server-side\n * event type doesn't break consumers.\n */\n eventType: OrganizationActivityEventType | string\n /** User who triggered the event, or `null` for system-emitted events. */\n actorUserId: string | null\n /** Resource the event is about — see {@link OrganizationActivityEventSubject}. */\n subject: OrganizationActivityEventSubject\n /** Optional payload (e.g. previous/current values on role/status changes). */\n metadata: Record<string, unknown> | null\n /** ISO-8601 timestamp of when the event occurred. */\n occurredAt: string\n}\n\n/**\n * Paginated page of activity events. The backend only echoes `items` and\n * `total`; `page` / `limit` are not in the response — they're the values\n * the caller asked for in {@link OrganizationActivityFilters}.\n */\nexport type OrganizationActivityPage = {\n items: OrganizationActivityEvent[]\n total: number\n}\n\n/** Filters accepted by `OrganizationsAPI.getOrganizationActivity`. */\nexport type OrganizationActivityFilters = {\n /**\n * Restrict to one or more event types. Accepts a single string, an enum\n * value, or an array (sent to the backend as a comma-separated list).\n */\n eventType?: OrganizationActivityEventType | string | Array<OrganizationActivityEventType | string>\n /** Restrict to events triggered by a specific user. */\n actorUserId?: string\n /** ISO-8601 lower bound (inclusive) on `occurredAt`. */\n from?: string\n /** ISO-8601 upper bound (exclusive) on `occurredAt`. */\n to?: string\n /** Page number — 1-based. */\n page?: number\n /** Page size — backend cap is 200. */\n limit?: number\n}\n\nexport type OrganizationMember = {\n createdAt: string\n updatedAt: string\n id: string\n userId: string\n orgId: string\n userAddress: string\n role: OrganizationMemberRole\n isActive: boolean\n}\n\nexport type OrganizationMembersResponse = {\n members: OrganizationMember[]\n total: number\n}\n\nexport type StripeCheckoutResult = {\n stripeAccountId: string\n stripeAccountLink: string\n userId: string\n userCountryCode: string\n linkCreatedAt: number\n linkExpiresAt: number\n}\n"]}
@@ -12,7 +12,7 @@
12
12
  * Callers can override the pin per `Payments` instance via
13
13
  * `options.version`.
14
14
  *
15
- * @see https://docs.nevermined.app/api-reference/versioning
15
+ * @see https://nevermined.ai/docs/development-guide/api-versioning
16
16
  */
17
17
  export declare const LOCKED_API_VERSION = "1.1";
18
18
  /**
@@ -12,7 +12,7 @@
12
12
  * Callers can override the pin per `Payments` instance via
13
13
  * `options.version`.
14
14
  *
15
- * @see https://docs.nevermined.app/api-reference/versioning
15
+ * @see https://nevermined.ai/docs/development-guide/api-versioning
16
16
  */
17
17
  export const LOCKED_API_VERSION = '1.1';
18
18
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"api-version.js","sourceRoot":"","sources":["../../src/common/api-version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAA","sourcesContent":["/**\n * The Nevermined **backend API** version (nvm-monorepo MAJOR.MINOR) this SDK\n * release is built and tested against — NOT the version of the SDK package\n * itself. Every HTTP request the SDK sends to the Nevermined backend carries\n * this value in the {@link API_VERSION_HEADER} header so the backend keeps\n * serving the matching API contract even after newer backend deployments.\n *\n * Bump this constant deliberately, and only when the SDK targets a newer\n * backend contract: update the value, run the e2e suite against a staging\n * backend running that version, then cut a minor SDK release.\n *\n * Callers can override the pin per `Payments` instance via\n * `options.version`.\n *\n * @see https://docs.nevermined.app/api-reference/versioning\n */\nexport const LOCKED_API_VERSION = '1.1'\n\n/**\n * Name of the HTTP request header carrying the backend API version the SDK\n * is pinned to. Sent on every backend call with the resolved instance\n * version (defaults to {@link LOCKED_API_VERSION}).\n */\nexport const API_VERSION_HEADER = 'Nevermined-Version'\n"]}
1
+ {"version":3,"file":"api-version.js","sourceRoot":"","sources":["../../src/common/api-version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAA","sourcesContent":["/**\n * The Nevermined **backend API** version (nvm-monorepo MAJOR.MINOR) this SDK\n * release is built and tested against — NOT the version of the SDK package\n * itself. Every HTTP request the SDK sends to the Nevermined backend carries\n * this value in the {@link API_VERSION_HEADER} header so the backend keeps\n * serving the matching API contract even after newer backend deployments.\n *\n * Bump this constant deliberately, and only when the SDK targets a newer\n * backend contract: update the value, run the e2e suite against a staging\n * backend running that version, then cut a minor SDK release.\n *\n * Callers can override the pin per `Payments` instance via\n * `options.version`.\n *\n * @see https://nevermined.ai/docs/development-guide/api-versioning\n */\nexport const LOCKED_API_VERSION = '1.1'\n\n/**\n * Name of the HTTP request header carrying the backend API version the SDK\n * is pinned to. Sent on every backend call with the resolved instance\n * version (defaults to {@link LOCKED_API_VERSION}).\n */\nexport const API_VERSION_HEADER = 'Nevermined-Version'\n"]}
@@ -9,10 +9,15 @@ export type PaymentScheme = 'nvm';
9
9
  export interface PaymentOptions {
10
10
  /**
11
11
  * The Nevermined environment to connect to.
12
- * If you are developing an agent it's recommended to use the "sandbox" environment.
13
- * When deploying to live use the "live" environment.
12
+ *
13
+ * @deprecated The environment is now derived from the NVM API key prefix
14
+ * (`<prefix>:<jwt>`), so this option is no longer required. It is still
15
+ * accepted for backward compatibility and as a fallback when the key prefix
16
+ * is unrecognized (e.g. local/custom development), but when the prefix maps
17
+ * to a known environment the key wins and this option is ignored (a one-time
18
+ * deprecation warning is emitted). It will be removed in a future release.
14
19
  */
15
- environment: EnvironmentName;
20
+ environment?: EnvironmentName;
16
21
  /**
17
22
  * The Nevermined API Key. This key identify your user and is required to interact with the Nevermined API.
18
23
  * You can get your API key by logging in to the Nevermined App.
@@ -38,7 +43,7 @@ export interface PaymentOptions {
38
43
  * built and tested against. Override only to deliberately target a
39
44
  * different backend contract.
40
45
  *
41
- * @see https://docs.nevermined.app/api-reference/versioning
46
+ * @see https://nevermined.ai/docs/development-guide/api-versioning
42
47
  */
43
48
  version?: string;
44
49
  /**