@nevermined-io/payments 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/agents-api.d.ts +4 -3
- package/dist/api/agents-api.d.ts.map +1 -1
- package/dist/api/agents-api.js +5 -5
- package/dist/api/agents-api.js.map +1 -1
- package/dist/api/base-payments.d.ts +49 -1
- package/dist/api/base-payments.d.ts.map +1 -1
- package/dist/api/base-payments.js +70 -6
- package/dist/api/base-payments.js.map +1 -1
- package/dist/api/nvm-api.d.ts +2 -0
- package/dist/api/nvm-api.d.ts.map +1 -1
- package/dist/api/nvm-api.js +2 -0
- package/dist/api/nvm-api.js.map +1 -1
- package/dist/api/organizations-api/organizations-api.d.ts +42 -1
- package/dist/api/organizations-api/organizations-api.d.ts.map +1 -1
- package/dist/api/organizations-api/organizations-api.js +91 -3
- package/dist/api/organizations-api/organizations-api.js.map +1 -1
- package/dist/api/organizations-api/types.d.ts +134 -0
- package/dist/api/organizations-api/types.d.ts.map +1 -1
- package/dist/api/organizations-api/types.js +52 -0
- package/dist/api/organizations-api/types.js.map +1 -1
- package/dist/api/plans-api.d.ts +6 -6
- package/dist/api/plans-api.d.ts.map +1 -1
- package/dist/api/plans-api.js +11 -11
- package/dist/api/plans-api.js.map +1 -1
- package/dist/common/types.d.ts +15 -0
- package/dist/common/types.d.ts.map +1 -1
- package/dist/common/types.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/payments.d.ts +27 -18
- package/dist/payments.d.ts.map +1 -1
- package/dist/payments.js +41 -1
- package/dist/payments.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PaymentsError } from '../../common/payments.error.js';
|
|
2
2
|
import { BasePaymentsAPI } from '../base-payments.js';
|
|
3
|
-
import { API_URL_CONNECT_STRIPE_ACCOUNT, API_URL_CREATE_USER, API_URL_GET_MEMBERS } from '../nvm-api.js';
|
|
3
|
+
import { API_URL_CONNECT_STRIPE_ACCOUNT, API_URL_CREATE_USER, API_URL_GET_MEMBERS, API_URL_MY_MEMBERSHIPS, API_URL_ORG_ACTIVITY, } from '../nvm-api.js';
|
|
4
4
|
export class OrganizationsAPI extends BasePaymentsAPI {
|
|
5
5
|
static getInstance(options) {
|
|
6
6
|
return new OrganizationsAPI(options);
|
|
@@ -59,6 +59,93 @@ export class OrganizationsAPI extends BasePaymentsAPI {
|
|
|
59
59
|
total: data.totalResults,
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Lists every organization the authenticated user is an active member of,
|
|
64
|
+
* with their role and the organization's tier.
|
|
65
|
+
*
|
|
66
|
+
* Powers workspace pickers in third-party tools built on the SDK, and the
|
|
67
|
+
* "where will this publish?" UX when a user belongs to multiple orgs.
|
|
68
|
+
*
|
|
69
|
+
* @returns An array of {@link MyMembership} — empty when the user has no
|
|
70
|
+
* active memberships and operates as a personal account.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const memberships = await payments.organizations.getMyMemberships()
|
|
75
|
+
* for (const m of memberships) {
|
|
76
|
+
* console.log(`${m.orgName} — ${m.role}`)
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
async getMyMemberships() {
|
|
81
|
+
const url = new URL(API_URL_MY_MEMBERSHIPS, this.environment.backend);
|
|
82
|
+
const options = this.getBackendHTTPOptions('GET');
|
|
83
|
+
const response = await fetch(url, options);
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
const error = await response.json().catch(() => ({ message: 'Unknown error' }));
|
|
86
|
+
throw PaymentsError.fromBackend('Unable to fetch memberships', error);
|
|
87
|
+
}
|
|
88
|
+
const data = (await response.json());
|
|
89
|
+
return Array.isArray(data) ? data : [];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Lists events emitted into the activity feed of an organization the
|
|
93
|
+
* caller is an active member of (member invites, customer events,
|
|
94
|
+
* subscription transitions, webhook deliveries, …).
|
|
95
|
+
*
|
|
96
|
+
* Requires the caller to be a Member or Admin of `orgId`; the backend
|
|
97
|
+
* returns 403 otherwise. Premium+ entitlement is enforced server-side.
|
|
98
|
+
*
|
|
99
|
+
* @param orgId - The organization id (e.g. `org-…`) whose feed to read.
|
|
100
|
+
* @param filters - Optional filter set — see {@link OrganizationActivityFilters}.
|
|
101
|
+
* @returns A paginated {@link OrganizationActivityPage}.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const page = await payments.organizations.getOrganizationActivity(orgId, {
|
|
106
|
+
* eventType: OrganizationActivityEventType.MemberInvited,
|
|
107
|
+
* page: 1,
|
|
108
|
+
* limit: 25,
|
|
109
|
+
* })
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
async getOrganizationActivity(orgId, filters = {}) {
|
|
113
|
+
if (!orgId) {
|
|
114
|
+
throw new PaymentsError('orgId is required');
|
|
115
|
+
}
|
|
116
|
+
const params = new URLSearchParams();
|
|
117
|
+
if (filters.eventType !== undefined) {
|
|
118
|
+
const eventType = Array.isArray(filters.eventType)
|
|
119
|
+
? filters.eventType.map(String).join(',')
|
|
120
|
+
: String(filters.eventType);
|
|
121
|
+
if (eventType.length > 0)
|
|
122
|
+
params.set('eventType', eventType);
|
|
123
|
+
}
|
|
124
|
+
if (filters.actorUserId)
|
|
125
|
+
params.set('actorUserId', filters.actorUserId);
|
|
126
|
+
if (filters.from)
|
|
127
|
+
params.set('from', filters.from);
|
|
128
|
+
if (filters.to)
|
|
129
|
+
params.set('to', filters.to);
|
|
130
|
+
if (filters.page !== undefined)
|
|
131
|
+
params.set('page', String(filters.page));
|
|
132
|
+
if (filters.limit !== undefined)
|
|
133
|
+
params.set('limit', String(filters.limit));
|
|
134
|
+
const path = API_URL_ORG_ACTIVITY.replace(':orgId', encodeURIComponent(orgId));
|
|
135
|
+
const queryString = params.toString();
|
|
136
|
+
const url = new URL(queryString ? `${path}?${queryString}` : path, this.environment.backend);
|
|
137
|
+
const options = this.getBackendHTTPOptions('GET');
|
|
138
|
+
const response = await fetch(url, options);
|
|
139
|
+
if (!response.ok) {
|
|
140
|
+
const error = await response.json().catch(() => ({ message: 'Unknown error' }));
|
|
141
|
+
throw PaymentsError.fromBackend('Unable to fetch organization activity', error);
|
|
142
|
+
}
|
|
143
|
+
const data = (await response.json());
|
|
144
|
+
return {
|
|
145
|
+
items: Array.isArray(data.items) ? data.items : [],
|
|
146
|
+
total: typeof data.total === 'number' ? data.total : 0,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
62
149
|
/**
|
|
63
150
|
* Connect user with Stripe
|
|
64
151
|
* @param userEmail - The email of the user
|
|
@@ -84,9 +171,10 @@ export class OrganizationsAPI extends BasePaymentsAPI {
|
|
|
84
171
|
return {
|
|
85
172
|
stripeAccountLink: data.stripeAccountLink,
|
|
86
173
|
stripeAccountId: data.stripeAccountId,
|
|
87
|
-
userId: data.userId,
|
|
174
|
+
userId: data.userId,
|
|
175
|
+
userCountryCode: data.userCountryCode,
|
|
88
176
|
linkCreatedAt: data.linkCreatedAt,
|
|
89
|
-
linkExpiresAt: data.linkExpiresAt
|
|
177
|
+
linkExpiresAt: data.linkExpiresAt,
|
|
90
178
|
};
|
|
91
179
|
}
|
|
92
180
|
}
|
|
@@ -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,EAAE,8BAA8B,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAGxG,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IACnD,MAA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,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,EAAE,eAAe,EACpC,IAAI,CAAC,eAAe;YACpB,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 { API_URL_CONNECT_STRIPE_ACCOUNT, API_URL_CREATE_USER, API_URL_GET_MEMBERS } from '../nvm-api.js'\nimport { CreateUserResponse, OrganizationMemberRole, OrganizationMembersResponse, StripeCheckoutResult } 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 * 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(userEmail: string, userCountryCode: string, returnUrl: string): 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, userCountryCode:\n 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;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'../../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"]}
|
|
@@ -3,12 +3,146 @@ export declare enum OrganizationMemberRole {
|
|
|
3
3
|
Member = "Member",
|
|
4
4
|
Client = "Client"
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Tier of an organization. Mirrors the backend `OrganizationType` enum at
|
|
8
|
+
* `libs/commons/src/lib/types/types.ts` in nvm-monorepo.
|
|
9
|
+
*
|
|
10
|
+
* - `Premium` / `Enterprise` — the paid tiers from Epic #1339.
|
|
11
|
+
* - `Lapsed` — an org whose paid subscription has expired; replaces the
|
|
12
|
+
* retired `Free` bucket (the backend never emits `Free` for new rows).
|
|
13
|
+
* - `Other` — legacy pre-tiered-pricing bucket still returned for orgs that
|
|
14
|
+
* pre-date the tier system; inherits Premium-equivalent caps and features
|
|
15
|
+
* server-side.
|
|
16
|
+
*/
|
|
17
|
+
export declare enum OrganizationType {
|
|
18
|
+
Premium = "Premium",
|
|
19
|
+
Enterprise = "Enterprise",
|
|
20
|
+
Lapsed = "Lapsed",
|
|
21
|
+
Other = "Other"
|
|
22
|
+
}
|
|
6
23
|
export type CreateUserResponse = {
|
|
7
24
|
nvmApiKey: string;
|
|
8
25
|
userId: string;
|
|
9
26
|
userWallet: string;
|
|
10
27
|
alreadyMember: boolean;
|
|
11
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* A single organization the authenticated user is an active member of.
|
|
31
|
+
* Returned by `OrganizationsAPI.getMyMemberships()` and used by clients to
|
|
32
|
+
* power workspace pickers and "where will this publish?" UX.
|
|
33
|
+
*
|
|
34
|
+
* Shape mirrors `MyMembershipDto` in the Nevermined backend
|
|
35
|
+
* (`apps/api/src/organizations/dto/my-membership.dto.ts`).
|
|
36
|
+
*/
|
|
37
|
+
export type MyMembership = {
|
|
38
|
+
/** Stable organization id (e.g. `org-…`). */
|
|
39
|
+
orgId: string;
|
|
40
|
+
/** Display name of the organization. */
|
|
41
|
+
orgName: string;
|
|
42
|
+
/** Caller's role inside this organization. */
|
|
43
|
+
role: OrganizationMemberRole;
|
|
44
|
+
/** Tier of the organization — see {@link OrganizationType}. */
|
|
45
|
+
orgType: OrganizationType;
|
|
46
|
+
/** Whether the caller is an Admin of this organization. */
|
|
47
|
+
isAdmin: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* `true` when the org has at least one `organizationSubscription` row —
|
|
50
|
+
* the org has previously been associated with a paid tier (active,
|
|
51
|
+
* past_due, trialing, lapsed, or canceled). Combined with
|
|
52
|
+
* `orgType === Lapsed` it distinguishes "subscription expired" from
|
|
53
|
+
* "free org that never subscribed".
|
|
54
|
+
*/
|
|
55
|
+
hasSubscriptionHistory: boolean;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Event types emitted into the organization activity feed. Values mirror
|
|
59
|
+
* the backend enum in `@nevermined-io/commons`. Stored on the wire as
|
|
60
|
+
* dot-namespaced lowercase strings — the SDK accepts any string for
|
|
61
|
+
* forward-compatibility when new event types are introduced server-side.
|
|
62
|
+
*/
|
|
63
|
+
export declare enum OrganizationActivityEventType {
|
|
64
|
+
MemberInvited = "member.invited",
|
|
65
|
+
MemberJoined = "member.joined",
|
|
66
|
+
MemberRoleChanged = "member.role_changed",
|
|
67
|
+
MemberDeactivated = "member.deactivated",
|
|
68
|
+
MemberReactivated = "member.reactivated",
|
|
69
|
+
MemberRemoved = "member.removed",
|
|
70
|
+
InvitationRevoked = "invitation.revoked",
|
|
71
|
+
InvitationExpired = "invitation.expired",
|
|
72
|
+
AgentCreated = "agent.created",
|
|
73
|
+
PlanCreated = "plan.created",
|
|
74
|
+
PlanPurchased = "plan.purchased",
|
|
75
|
+
CustomerAdded = "customer.added",
|
|
76
|
+
CustomerBlocked = "customer.blocked",
|
|
77
|
+
CustomerUnblocked = "customer.unblocked",
|
|
78
|
+
SubscriptionUpgraded = "subscription.upgraded",
|
|
79
|
+
SubscriptionDowngraded = "subscription.downgraded",
|
|
80
|
+
SubscriptionCanceled = "subscription.canceled",
|
|
81
|
+
SubscriptionLapsed = "subscription.lapsed",
|
|
82
|
+
WebhookDelivered = "webhook.delivered",
|
|
83
|
+
WebhookFailed = "webhook.failed"
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The resource an activity event is about. `kind` describes the resource
|
|
87
|
+
* type (`plan`, `agent`, `member`, `subscription`, `invitation`, `customer`,
|
|
88
|
+
* `webhook`) and `id` is the resource's identifier. Extras vary by kind —
|
|
89
|
+
* e.g. invitations include `role` + `email`, members include `role` +
|
|
90
|
+
* `userId`, subscriptions include `tier`.
|
|
91
|
+
*/
|
|
92
|
+
export type OrganizationActivityEventSubject = {
|
|
93
|
+
kind: string;
|
|
94
|
+
id: string;
|
|
95
|
+
[key: string]: unknown;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* A single event emitted into the organization activity feed. Shape mirrors
|
|
99
|
+
* `OrganizationActivityEventResponseDto` in the Nevermined backend.
|
|
100
|
+
*/
|
|
101
|
+
export type OrganizationActivityEvent = {
|
|
102
|
+
/** Activity event ID (e.g. `ae-{uuid}`). */
|
|
103
|
+
id: string;
|
|
104
|
+
/**
|
|
105
|
+
* Backend-emitted event type. Use {@link OrganizationActivityEventType}
|
|
106
|
+
* for known values; the field stays a plain string so a new server-side
|
|
107
|
+
* event type doesn't break consumers.
|
|
108
|
+
*/
|
|
109
|
+
eventType: OrganizationActivityEventType | string;
|
|
110
|
+
/** User who triggered the event, or `null` for system-emitted events. */
|
|
111
|
+
actorUserId: string | null;
|
|
112
|
+
/** Resource the event is about — see {@link OrganizationActivityEventSubject}. */
|
|
113
|
+
subject: OrganizationActivityEventSubject;
|
|
114
|
+
/** Optional payload (e.g. previous/current values on role/status changes). */
|
|
115
|
+
metadata: Record<string, unknown> | null;
|
|
116
|
+
/** ISO-8601 timestamp of when the event occurred. */
|
|
117
|
+
occurredAt: string;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Paginated page of activity events. The backend only echoes `items` and
|
|
121
|
+
* `total`; `page` / `limit` are not in the response — they're the values
|
|
122
|
+
* the caller asked for in {@link OrganizationActivityFilters}.
|
|
123
|
+
*/
|
|
124
|
+
export type OrganizationActivityPage = {
|
|
125
|
+
items: OrganizationActivityEvent[];
|
|
126
|
+
total: number;
|
|
127
|
+
};
|
|
128
|
+
/** Filters accepted by `OrganizationsAPI.getOrganizationActivity`. */
|
|
129
|
+
export type OrganizationActivityFilters = {
|
|
130
|
+
/**
|
|
131
|
+
* Restrict to one or more event types. Accepts a single string, an enum
|
|
132
|
+
* value, or an array (sent to the backend as a comma-separated list).
|
|
133
|
+
*/
|
|
134
|
+
eventType?: OrganizationActivityEventType | string | Array<OrganizationActivityEventType | string>;
|
|
135
|
+
/** Restrict to events triggered by a specific user. */
|
|
136
|
+
actorUserId?: string;
|
|
137
|
+
/** ISO-8601 lower bound (inclusive) on `occurredAt`. */
|
|
138
|
+
from?: string;
|
|
139
|
+
/** ISO-8601 upper bound (exclusive) on `occurredAt`. */
|
|
140
|
+
to?: string;
|
|
141
|
+
/** Page number — 1-based. */
|
|
142
|
+
page?: number;
|
|
143
|
+
/** Page size — backend cap is 200. */
|
|
144
|
+
limit?: number;
|
|
145
|
+
};
|
|
12
146
|
export type OrganizationMember = {
|
|
13
147
|
createdAt: string;
|
|
14
148
|
updatedAt: string;
|
|
@@ -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,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,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;;;;;;;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,6BA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BAA6B,GAAG,MAAM,GAAG,KAAK,CAAC,6BAA6B,GAAG,MAAM,CAAC,CAAA;IAClG,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,wDAAwD;IACxD,EAAE,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"}
|
|
@@ -4,4 +4,56 @@ export var OrganizationMemberRole;
|
|
|
4
4
|
OrganizationMemberRole["Member"] = "Member";
|
|
5
5
|
OrganizationMemberRole["Client"] = "Client";
|
|
6
6
|
})(OrganizationMemberRole || (OrganizationMemberRole = {}));
|
|
7
|
+
/**
|
|
8
|
+
* Tier of an organization. Mirrors the backend `OrganizationType` enum at
|
|
9
|
+
* `libs/commons/src/lib/types/types.ts` in nvm-monorepo.
|
|
10
|
+
*
|
|
11
|
+
* - `Premium` / `Enterprise` — the paid tiers from Epic #1339.
|
|
12
|
+
* - `Lapsed` — an org whose paid subscription has expired; replaces the
|
|
13
|
+
* retired `Free` bucket (the backend never emits `Free` for new rows).
|
|
14
|
+
* - `Other` — legacy pre-tiered-pricing bucket still returned for orgs that
|
|
15
|
+
* pre-date the tier system; inherits Premium-equivalent caps and features
|
|
16
|
+
* server-side.
|
|
17
|
+
*/
|
|
18
|
+
export var OrganizationType;
|
|
19
|
+
(function (OrganizationType) {
|
|
20
|
+
OrganizationType["Premium"] = "Premium";
|
|
21
|
+
OrganizationType["Enterprise"] = "Enterprise";
|
|
22
|
+
OrganizationType["Lapsed"] = "Lapsed";
|
|
23
|
+
OrganizationType["Other"] = "Other";
|
|
24
|
+
})(OrganizationType || (OrganizationType = {}));
|
|
25
|
+
/**
|
|
26
|
+
* Event types emitted into the organization activity feed. Values mirror
|
|
27
|
+
* the backend enum in `@nevermined-io/commons`. Stored on the wire as
|
|
28
|
+
* dot-namespaced lowercase strings — the SDK accepts any string for
|
|
29
|
+
* forward-compatibility when new event types are introduced server-side.
|
|
30
|
+
*/
|
|
31
|
+
export var OrganizationActivityEventType;
|
|
32
|
+
(function (OrganizationActivityEventType) {
|
|
33
|
+
// Membership lifecycle
|
|
34
|
+
OrganizationActivityEventType["MemberInvited"] = "member.invited";
|
|
35
|
+
OrganizationActivityEventType["MemberJoined"] = "member.joined";
|
|
36
|
+
OrganizationActivityEventType["MemberRoleChanged"] = "member.role_changed";
|
|
37
|
+
OrganizationActivityEventType["MemberDeactivated"] = "member.deactivated";
|
|
38
|
+
OrganizationActivityEventType["MemberReactivated"] = "member.reactivated";
|
|
39
|
+
OrganizationActivityEventType["MemberRemoved"] = "member.removed";
|
|
40
|
+
OrganizationActivityEventType["InvitationRevoked"] = "invitation.revoked";
|
|
41
|
+
OrganizationActivityEventType["InvitationExpired"] = "invitation.expired";
|
|
42
|
+
// Resource lifecycle
|
|
43
|
+
OrganizationActivityEventType["AgentCreated"] = "agent.created";
|
|
44
|
+
OrganizationActivityEventType["PlanCreated"] = "plan.created";
|
|
45
|
+
OrganizationActivityEventType["PlanPurchased"] = "plan.purchased";
|
|
46
|
+
// Customer lifecycle
|
|
47
|
+
OrganizationActivityEventType["CustomerAdded"] = "customer.added";
|
|
48
|
+
OrganizationActivityEventType["CustomerBlocked"] = "customer.blocked";
|
|
49
|
+
OrganizationActivityEventType["CustomerUnblocked"] = "customer.unblocked";
|
|
50
|
+
// Subscription lifecycle
|
|
51
|
+
OrganizationActivityEventType["SubscriptionUpgraded"] = "subscription.upgraded";
|
|
52
|
+
OrganizationActivityEventType["SubscriptionDowngraded"] = "subscription.downgraded";
|
|
53
|
+
OrganizationActivityEventType["SubscriptionCanceled"] = "subscription.canceled";
|
|
54
|
+
OrganizationActivityEventType["SubscriptionLapsed"] = "subscription.lapsed";
|
|
55
|
+
// Webhook delivery
|
|
56
|
+
OrganizationActivityEventType["WebhookDelivered"] = "webhook.delivered";
|
|
57
|
+
OrganizationActivityEventType["WebhookFailed"] = "webhook.failed";
|
|
58
|
+
})(OrganizationActivityEventType || (OrganizationActivityEventType = {}));
|
|
7
59
|
//# sourceMappingURL=types.js.map
|
|
@@ -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","sourcesContent":["export enum OrganizationMemberRole {\n Admin = 'Admin',\n Member = 'Member',\n Client = 'Client',\n}\n\nexport type CreateUserResponse = {\n nvmApiKey: string\n userId: string\n userWallet: string\n alreadyMember: boolean\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}"]}
|
|
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"]}
|
package/dist/api/plans-api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, Currency, NvmAPIResult, PaginationOptions, PaymentOptions, PlanBalance, PlanCreditsConfig, PlanRedemptionType, PlanMetadata, PlanPriceConfig, StripeCheckoutResult } from '../common/types.js';
|
|
2
|
-
import { BasePaymentsAPI } from './base-payments.js';
|
|
2
|
+
import { BasePaymentsAPI, PublicationOptions } from './base-payments.js';
|
|
3
3
|
/**
|
|
4
4
|
* The PlansAPI class provides methods to register and interact with payment plans on Nevermined.
|
|
5
5
|
*/
|
|
@@ -154,7 +154,7 @@ export declare class PlansAPI extends BasePaymentsAPI {
|
|
|
154
154
|
*
|
|
155
155
|
* @returns The unique identifier of the plan (Plan ID) of the newly created plan.
|
|
156
156
|
*/
|
|
157
|
-
registerPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, nonce?: bigint, accessLimit?: 'credits' | 'time'): Promise<{
|
|
157
|
+
registerPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, nonce?: bigint, accessLimit?: 'credits' | 'time', publicationOptions?: PublicationOptions): Promise<{
|
|
158
158
|
planId: string;
|
|
159
159
|
}>;
|
|
160
160
|
/**
|
|
@@ -187,7 +187,7 @@ export declare class PlansAPI extends BasePaymentsAPI {
|
|
|
187
187
|
*
|
|
188
188
|
* @returns The unique identifier of the plan (Plan ID) of the newly created plan.
|
|
189
189
|
*/
|
|
190
|
-
registerCreditsPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig): Promise<{
|
|
190
|
+
registerCreditsPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, publicationOptions?: PublicationOptions): Promise<{
|
|
191
191
|
planId: string;
|
|
192
192
|
}>;
|
|
193
193
|
/**
|
|
@@ -220,7 +220,7 @@ export declare class PlansAPI extends BasePaymentsAPI {
|
|
|
220
220
|
*
|
|
221
221
|
* @returns The unique identifier of the plan (Plan ID) of the newly created plan.
|
|
222
222
|
*/
|
|
223
|
-
registerTimePlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig): Promise<{
|
|
223
|
+
registerTimePlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, publicationOptions?: PublicationOptions): Promise<{
|
|
224
224
|
planId: string;
|
|
225
225
|
}>;
|
|
226
226
|
/**
|
|
@@ -251,7 +251,7 @@ export declare class PlansAPI extends BasePaymentsAPI {
|
|
|
251
251
|
*
|
|
252
252
|
* @returns The unique identifier of the plan (Plan ID) of the newly created plan.
|
|
253
253
|
*/
|
|
254
|
-
registerCreditsTrialPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig): Promise<{
|
|
254
|
+
registerCreditsTrialPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, publicationOptions?: PublicationOptions): Promise<{
|
|
255
255
|
planId: string;
|
|
256
256
|
}>;
|
|
257
257
|
/**
|
|
@@ -282,7 +282,7 @@ export declare class PlansAPI extends BasePaymentsAPI {
|
|
|
282
282
|
*
|
|
283
283
|
* @returns The unique identifier of the plan (Plan ID) of the newly created plan.
|
|
284
284
|
*/
|
|
285
|
-
registerTimeTrialPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig): Promise<{
|
|
285
|
+
registerTimeTrialPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, publicationOptions?: PublicationOptions): Promise<{
|
|
286
286
|
planId: string;
|
|
287
287
|
}>;
|
|
288
288
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plans-api.d.ts","sourceRoot":"","sources":["../../src/api/plans-api.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,QAAQ,EAER,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"plans-api.d.ts","sourceRoot":"","sources":["../../src/api/plans-api.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,QAAQ,EAER,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAA6B,MAAM,oBA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,CAAC,YAAY,CAAC;CAWzB"}
|
package/dist/api/plans-api.js
CHANGED
|
@@ -2,7 +2,7 @@ import { PaymentsError } from '../common/payments.error.js';
|
|
|
2
2
|
import { Currency, EURC_TOKEN_ADDRESS, PaginationOptions, } from '../common/types.js';
|
|
3
3
|
import { ZeroAddress } from '../environments.js';
|
|
4
4
|
import { getRandomBigInt, isEthereumAddress } from '../utils.js';
|
|
5
|
-
import { BasePaymentsAPI } from './base-payments.js';
|
|
5
|
+
import { BasePaymentsAPI, resolvePublicationHeaders } from './base-payments.js';
|
|
6
6
|
import * as Plans from '../plans.js';
|
|
7
7
|
import { ContractsAPI } from './contracts-api.js';
|
|
8
8
|
import { API_URL_GET_PLAN, API_URL_GET_PLAN_AGENTS, API_URL_MINT_EXPIRABLE_PLAN, API_URL_MINT_PLAN, API_URL_ORDER_PLAN, API_URL_PLAN_BALANCE, API_URL_REGISTER_PLAN, API_URL_STRIPE_CHECKOUT, API_URL_GET_PLANS, } from './nvm-api.js';
|
|
@@ -193,7 +193,7 @@ export class PlansAPI extends BasePaymentsAPI {
|
|
|
193
193
|
*
|
|
194
194
|
* @returns The unique identifier of the plan (Plan ID) of the newly created plan.
|
|
195
195
|
*/
|
|
196
|
-
async registerPlan(planMetadata, priceConfig, creditsConfig, nonce = getRandomBigInt(), accessLimit) {
|
|
196
|
+
async registerPlan(planMetadata, priceConfig, creditsConfig, nonce = getRandomBigInt(), accessLimit, publicationOptions) {
|
|
197
197
|
if (accessLimit && !['credits', 'time'].includes(accessLimit)) {
|
|
198
198
|
throw new PaymentsError('Invalid access limit', 'accessLimit must be either "credits" or "time"');
|
|
199
199
|
}
|
|
@@ -209,7 +209,7 @@ export class PlansAPI extends BasePaymentsAPI {
|
|
|
209
209
|
accessLimit,
|
|
210
210
|
...(priceConfig.currency && { currency: priceConfig.currency }),
|
|
211
211
|
};
|
|
212
|
-
const options = this.getBackendHTTPOptions('POST', body);
|
|
212
|
+
const options = this.getBackendHTTPOptions('POST', body, resolvePublicationHeaders(publicationOptions));
|
|
213
213
|
const url = new URL(API_URL_REGISTER_PLAN, this.environment.backend);
|
|
214
214
|
const response = await fetch(url, options);
|
|
215
215
|
if (!response.ok) {
|
|
@@ -247,13 +247,13 @@ export class PlansAPI extends BasePaymentsAPI {
|
|
|
247
247
|
*
|
|
248
248
|
* @returns The unique identifier of the plan (Plan ID) of the newly created plan.
|
|
249
249
|
*/
|
|
250
|
-
async registerCreditsPlan(planMetadata, priceConfig, creditsConfig) {
|
|
250
|
+
async registerCreditsPlan(planMetadata, priceConfig, creditsConfig, publicationOptions) {
|
|
251
251
|
// Credits plans must have durationSecs = 0 (non-expirable) and either fixed or dynamic redemption
|
|
252
252
|
if (BigInt(creditsConfig.durationSecs) !== 0n)
|
|
253
253
|
throw new PaymentsError('The creditsConfig.durationSecs must be 0 for credits plans (non-expirable)');
|
|
254
254
|
if (creditsConfig.minAmount > creditsConfig.maxAmount)
|
|
255
255
|
throw new PaymentsError('The creditsConfig.minAmount can not be more than creditsConfig.maxAmount');
|
|
256
|
-
return this.registerPlan(planMetadata, priceConfig, creditsConfig, undefined, 'credits');
|
|
256
|
+
return this.registerPlan(planMetadata, priceConfig, creditsConfig, undefined, 'credits', publicationOptions);
|
|
257
257
|
}
|
|
258
258
|
/**
|
|
259
259
|
*
|
|
@@ -285,13 +285,13 @@ export class PlansAPI extends BasePaymentsAPI {
|
|
|
285
285
|
*
|
|
286
286
|
* @returns The unique identifier of the plan (Plan ID) of the newly created plan.
|
|
287
287
|
*/
|
|
288
|
-
async registerTimePlan(planMetadata, priceConfig, creditsConfig) {
|
|
288
|
+
async registerTimePlan(planMetadata, priceConfig, creditsConfig, publicationOptions) {
|
|
289
289
|
// Time plans must have durationSecs > 0 (expirable) and isRedemptionAmountFixed = false
|
|
290
290
|
if (BigInt(creditsConfig.durationSecs) === 0n)
|
|
291
291
|
throw new PaymentsError('The creditsConfig.durationSecs must be greater than 0 for time plans (expirable)');
|
|
292
292
|
if (creditsConfig.isRedemptionAmountFixed)
|
|
293
293
|
throw new PaymentsError('The creditsConfig.isRedemptionAmountFixed must be false for time plans');
|
|
294
|
-
return this.registerPlan(planMetadata, priceConfig, creditsConfig, undefined, 'time');
|
|
294
|
+
return this.registerPlan(planMetadata, priceConfig, creditsConfig, undefined, 'time', publicationOptions);
|
|
295
295
|
}
|
|
296
296
|
/**
|
|
297
297
|
*
|
|
@@ -321,9 +321,9 @@ export class PlansAPI extends BasePaymentsAPI {
|
|
|
321
321
|
*
|
|
322
322
|
* @returns The unique identifier of the plan (Plan ID) of the newly created plan.
|
|
323
323
|
*/
|
|
324
|
-
async registerCreditsTrialPlan(planMetadata, priceConfig, creditsConfig) {
|
|
324
|
+
async registerCreditsTrialPlan(planMetadata, priceConfig, creditsConfig, publicationOptions) {
|
|
325
325
|
planMetadata.isTrialPlan = true;
|
|
326
|
-
return this.registerCreditsPlan(planMetadata, priceConfig, creditsConfig);
|
|
326
|
+
return this.registerCreditsPlan(planMetadata, priceConfig, creditsConfig, publicationOptions);
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
329
329
|
*
|
|
@@ -353,9 +353,9 @@ export class PlansAPI extends BasePaymentsAPI {
|
|
|
353
353
|
*
|
|
354
354
|
* @returns The unique identifier of the plan (Plan ID) of the newly created plan.
|
|
355
355
|
*/
|
|
356
|
-
async registerTimeTrialPlan(planMetadata, priceConfig, creditsConfig) {
|
|
356
|
+
async registerTimeTrialPlan(planMetadata, priceConfig, creditsConfig, publicationOptions) {
|
|
357
357
|
planMetadata.isTrialPlan = true;
|
|
358
|
-
return this.registerTimePlan(planMetadata, priceConfig, creditsConfig);
|
|
358
|
+
return this.registerTimePlan(planMetadata, priceConfig, creditsConfig, publicationOptions);
|
|
359
359
|
}
|
|
360
360
|
/**
|
|
361
361
|
* Gets the information about a Payment Plan by its identifier.
|