@dev.smartpricing/platform-layer 0.0.2
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/_shared/billingCreditNotes.ts +24 -0
- package/_shared/billingDocumentSubscriptions.ts +36 -0
- package/_shared/billingDocuments.ts +32 -0
- package/_shared/billingInvoices.ts +24 -0
- package/_shared/billingLegalEntities.ts +109 -0
- package/_shared/billingOverview.ts +15 -0
- package/_shared/billingPaymentMethods.ts +89 -0
- package/_shared/billingSubscriptions.ts +54 -0
- package/_shared/common.ts +34 -0
- package/_shared/crossSelling.ts +21 -0
- package/_shared/index.ts +22 -0
- package/_shared/meContext.ts +15 -0
- package/_shared/members.ts +23 -0
- package/_shared/mfa.ts +75 -0
- package/_shared/organizationContext.ts +18 -0
- package/_shared/organizations.ts +46 -0
- package/_shared/password.ts +22 -0
- package/_shared/permissions.ts +16 -0
- package/_shared/products.ts +49 -0
- package/_shared/properties.ts +16 -0
- package/_shared/subscriptionCancellation.ts +17 -0
- package/_shared/unitTypes.ts +16 -0
- package/_shared/user.ts +77 -0
- package/app/components/.gitkeep +0 -0
- package/app/composables/apiClient.composable.ts +25 -0
- package/app/composables/useAuth.composable.ts +17 -0
- package/app/mutations/useAccountingLogin.mutation.ts +10 -0
- package/app/mutations/useActivate.mutation.ts +10 -0
- package/app/mutations/useChangePassword.mutation.ts +10 -0
- package/app/mutations/useCreatePaymentMethod.mutation.ts +13 -0
- package/app/mutations/useCreateSetupIntent.mutation.ts +13 -0
- package/app/mutations/useLogin.mutation.ts +10 -0
- package/app/mutations/useLogout.mutation.ts +7 -0
- package/app/mutations/useMfaDisable.mutation.ts +10 -0
- package/app/mutations/useMfaFinalize.mutation.ts +10 -0
- package/app/mutations/useMfaRegenerateRecoveryCodes.mutation.ts +10 -0
- package/app/mutations/useMfaSetup.mutation.ts +10 -0
- package/app/mutations/useMfaStepUp.mutation.ts +10 -0
- package/app/mutations/useRefresh.mutation.ts +7 -0
- package/app/mutations/useRemovePaymentMethod.mutation.ts +11 -0
- package/app/mutations/useRequestLegalEntityChange.mutation.ts +13 -0
- package/app/mutations/useRequestPasswordReset.mutation.ts +10 -0
- package/app/mutations/useRequestSubscriptionCancellation.mutation.ts +13 -0
- package/app/mutations/useResetPassword.mutation.ts +10 -0
- package/app/mutations/useSetPrimaryPaymentMethod.mutation.ts +13 -0
- package/app/mutations/useUpdateLegalEntity.mutation.ts +13 -0
- package/app/mutations/useUpdateProfile.mutation.ts +10 -0
- package/app/queries/useBillingDocumentPdf.query.ts +22 -0
- package/app/queries/useBillingDocuments.query.ts +35 -0
- package/app/queries/useBillingOverview.query.ts +17 -0
- package/app/queries/useCrossSelling.query.ts +14 -0
- package/app/queries/useLegalEntity.query.ts +20 -0
- package/app/queries/useOrganization.query.ts +17 -0
- package/app/queries/usePermissions.query.ts +14 -0
- package/app/queries/useSession.query.ts +14 -0
- package/app/utils/apiClient.utils.ts +134 -0
- package/nuxt.config.ts +50 -0
- package/package.json +34 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
const BundleSchema = z.object({
|
|
4
|
+
enabled: z.boolean(),
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
export const PermissionsResponseSchema = z.object({
|
|
8
|
+
products: z.object({
|
|
9
|
+
pricing: BundleSchema,
|
|
10
|
+
connect: BundleSchema,
|
|
11
|
+
chat: BundleSchema,
|
|
12
|
+
smartpms: BundleSchema,
|
|
13
|
+
}),
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export type PermissionsResponse = z.infer<typeof PermissionsResponseSchema>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
export const SuiteProductSchema = z.enum(['pms', 'pricing', 'chat', 'connect'])
|
|
4
|
+
|
|
5
|
+
export const SuiteLinkSchema = z.object({
|
|
6
|
+
value: SuiteProductSchema,
|
|
7
|
+
/** Bold "Smart" prefix shown in the brand-dark color. */
|
|
8
|
+
prefix: z.string(),
|
|
9
|
+
/** Suffix shown in the violet brand color (e.g. "pms", "pricing"). */
|
|
10
|
+
suffix: z.string(),
|
|
11
|
+
/** Translation key for the tagline shown under the product name. */
|
|
12
|
+
taglineKey: z.string(),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export const OrgProductStatusSchema = z.enum(['active', 'trial', 'not_subscribed'])
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Billing context surfaced when a paying customer cannot access a product —
|
|
19
|
+
* lets the UI explain *why* access is blocked (e.g. an unpaid invoice).
|
|
20
|
+
*/
|
|
21
|
+
export const ProductBlockedReasonSchema = z.object({
|
|
22
|
+
hasActiveSubscription: z.boolean(),
|
|
23
|
+
daysOverdue: z.number().nullable(),
|
|
24
|
+
oldestUnpaidDueDate: z.string().nullable(),
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const OrgProductRowSchema = SuiteLinkSchema.extend({
|
|
28
|
+
available: z.boolean(),
|
|
29
|
+
lifecycleMode: z.string().optional(),
|
|
30
|
+
status: OrgProductStatusSchema,
|
|
31
|
+
blockedReason: ProductBlockedReasonSchema.optional(),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
export const ListSuiteLinksResponseSchema = z.object({
|
|
35
|
+
items: z.array(SuiteLinkSchema),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export const ListOrgProductsResponseSchema = z.object({
|
|
39
|
+
items: z.array(OrgProductRowSchema),
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
export type SuiteProduct = z.infer<typeof SuiteProductSchema>
|
|
43
|
+
export type SuiteLink = z.infer<typeof SuiteLinkSchema>
|
|
44
|
+
export type OrgProductStatus = z.infer<typeof OrgProductStatusSchema>
|
|
45
|
+
export type ProductBlockedReason = z.infer<typeof ProductBlockedReasonSchema>
|
|
46
|
+
export type OrgProductRow = z.infer<typeof OrgProductRowSchema>
|
|
47
|
+
|
|
48
|
+
export type ListSuiteLinksResponse = z.infer<typeof ListSuiteLinksResponseSchema>
|
|
49
|
+
export type ListOrgProductsResponse = z.infer<typeof ListOrgProductsResponseSchema>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { UuidSchema } from './common.js'
|
|
3
|
+
|
|
4
|
+
export const PropertySchema = z.object({
|
|
5
|
+
id: UuidSchema,
|
|
6
|
+
organizationId: UuidSchema,
|
|
7
|
+
name: z.string(),
|
|
8
|
+
location: z.string().nullable().optional(),
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const ListPropertiesResponseSchema = z.object({
|
|
12
|
+
items: z.array(PropertySchema),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export type Property = z.infer<typeof PropertySchema>
|
|
16
|
+
export type ListPropertiesResponse = z.infer<typeof ListPropertiesResponseSchema>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
export const SubscriptionCancellationRequestSchema = z.object({
|
|
4
|
+
legalEntityId: z.string().min(1),
|
|
5
|
+
subscriptionIds: z.array(z.string().min(1)).min(1),
|
|
6
|
+
reasons: z.array(z.string()).min(1),
|
|
7
|
+
otherReasons: z.string(),
|
|
8
|
+
keepSendingPrices: z.boolean().optional(),
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const SubscriptionCancellationResponseSchema = z.object({
|
|
12
|
+
emails_status: z.enum(['sent', 'failed']),
|
|
13
|
+
zapier_status: z.enum(['sent', 'skipped', 'failed']),
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export type SubscriptionCancellationRequest = z.infer<typeof SubscriptionCancellationRequestSchema>
|
|
17
|
+
export type SubscriptionCancellationResponse = z.infer<typeof SubscriptionCancellationResponseSchema>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { UuidSchema } from './common.js'
|
|
3
|
+
|
|
4
|
+
export const UnitTypeSchema = z.object({
|
|
5
|
+
id: UuidSchema,
|
|
6
|
+
propertyId: UuidSchema,
|
|
7
|
+
name: z.string(),
|
|
8
|
+
numUnits: z.number().int(),
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const ListUnitTypesResponseSchema = z.object({
|
|
12
|
+
items: z.array(UnitTypeSchema),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export type UnitType = z.infer<typeof UnitTypeSchema>
|
|
16
|
+
export type ListUnitTypesResponse = z.infer<typeof ListUnitTypesResponseSchema>
|
package/_shared/user.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { UuidSchema } from './common.js'
|
|
3
|
+
import { PasswordSchema } from './password.js'
|
|
4
|
+
|
|
5
|
+
export const UserSchema = z.object({
|
|
6
|
+
id: UuidSchema,
|
|
7
|
+
email: z.string().email(),
|
|
8
|
+
firstName: z.string(),
|
|
9
|
+
lastName: z.string(),
|
|
10
|
+
name: z.string(),
|
|
11
|
+
locale: z.string().nullable(),
|
|
12
|
+
phone: z.string().nullable(),
|
|
13
|
+
/** Whether the user has TOTP MFA enabled. Surfaced so the SPA can render the right UI on /account/profile. */
|
|
14
|
+
mfaEnabled: z.boolean(),
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const LoginRequestSchema = z.object({
|
|
18
|
+
email: z.string().email(),
|
|
19
|
+
password: z.string().min(1),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export const ActivateRequestSchema = z.object({
|
|
23
|
+
token: z.string().min(1),
|
|
24
|
+
password: PasswordSchema,
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const ForgotPasswordRequestSchema = z.object({
|
|
28
|
+
email: z.string().email(),
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export const ResetPasswordRequestSchema = z.object({
|
|
32
|
+
token: z.string().min(1),
|
|
33
|
+
password: PasswordSchema,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export const AccountingLoginRequestSchema = z.object({
|
|
37
|
+
accountingToken: z.string().min(1),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export const UpdateProfileRequestSchema = z.object({
|
|
41
|
+
firstName: z.string().trim().min(1).optional(),
|
|
42
|
+
lastName: z.string().trim().min(1).optional(),
|
|
43
|
+
phone: z.string().nullable().optional(),
|
|
44
|
+
locale: z.string().nullable().optional(),
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
export const ChangePasswordRequestSchema = z.object({
|
|
48
|
+
currentPassword: z.string().min(1),
|
|
49
|
+
newPassword: PasswordSchema,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
export const UpdateProfileResponseSchema = z.object({
|
|
53
|
+
user: UserSchema,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
export const SessionResponseSchema = z.object({
|
|
57
|
+
user: UserSchema,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
export type User = z.infer<typeof UserSchema>
|
|
61
|
+
|
|
62
|
+
export type LoginRequest = z.infer<typeof LoginRequestSchema>
|
|
63
|
+
|
|
64
|
+
export type ActivateRequest = z.infer<typeof ActivateRequestSchema>
|
|
65
|
+
|
|
66
|
+
export type ForgotPasswordRequest = z.infer<typeof ForgotPasswordRequestSchema>
|
|
67
|
+
|
|
68
|
+
export type ResetPasswordRequest = z.infer<typeof ResetPasswordRequestSchema>
|
|
69
|
+
|
|
70
|
+
export type AccountingLoginRequest = z.infer<typeof AccountingLoginRequestSchema>
|
|
71
|
+
|
|
72
|
+
export type UpdateProfileRequest = z.infer<typeof UpdateProfileRequestSchema>
|
|
73
|
+
export type UpdateProfileResponse = z.infer<typeof UpdateProfileResponseSchema>
|
|
74
|
+
|
|
75
|
+
export type ChangePasswordRequest = z.infer<typeof ChangePasswordRequestSchema>
|
|
76
|
+
|
|
77
|
+
export type SessionResponse = z.infer<typeof SessionResponseSchema>
|
|
File without changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function useApiClient() {
|
|
2
|
+
const { BACKEND_BASE_URL, ENV_CSRF_COOKIE_NAME, PLATFORM_URL } = useRuntimeConfig().public
|
|
3
|
+
|
|
4
|
+
return createApiClient({
|
|
5
|
+
baseURL: BACKEND_BASE_URL as string,
|
|
6
|
+
csrf: {
|
|
7
|
+
cookieName: (ENV_CSRF_COOKIE_NAME as string) || 'smt_csrf',
|
|
8
|
+
},
|
|
9
|
+
auth: {
|
|
10
|
+
refreshBaseURL: BACKEND_BASE_URL as string,
|
|
11
|
+
platformURL: (PLATFORM_URL as string) || '',
|
|
12
|
+
mfa: {
|
|
13
|
+
shouldChallenge: (_status: number, data: unknown) => {
|
|
14
|
+
const code = (data as { error?: { code?: string } } | undefined)?.error?.code
|
|
15
|
+
return code === 'otp_required'
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
onRefreshFailed: () => {
|
|
19
|
+
if (import.meta.client) {
|
|
20
|
+
window.location.assign(`${PLATFORM_URL}/auth/login`)
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function useAuth() {
|
|
2
|
+
const { PLATFORM_URL } = useRuntimeConfig().public
|
|
3
|
+
const { mutateAsync: logout, status, error } = useLogoutMutation()
|
|
4
|
+
|
|
5
|
+
async function signOut() {
|
|
6
|
+
await logout()
|
|
7
|
+
if (import.meta.client) {
|
|
8
|
+
window.location.assign(`${PLATFORM_URL}/auth/login`)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
signOut,
|
|
14
|
+
logoutStatus: status,
|
|
15
|
+
logoutError: error,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AccountingLoginRequest } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useAccountingLoginMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: AccountingLoginRequest) =>
|
|
8
|
+
client<void>('/api/auth/accounting-login', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ActivateRequest } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useActivateMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: ActivateRequest) =>
|
|
8
|
+
client<void>('/api/auth/activate', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ChangePasswordRequest } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useChangePasswordMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: ChangePasswordRequest) =>
|
|
8
|
+
client<{ ok: true }>('/api/me/change-password', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CreatePaymentMethodRequest, CreatePaymentMethodsResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useCreatePaymentMethodMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (params: { orgId: string; body: CreatePaymentMethodRequest }) =>
|
|
8
|
+
client<CreatePaymentMethodsResponse>(
|
|
9
|
+
`/api/orgs/${encodeURIComponent(params.orgId)}/billing/payment-methods`,
|
|
10
|
+
{ method: 'POST', body: params.body },
|
|
11
|
+
),
|
|
12
|
+
})
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CreateSetupIntentRequest, CreateSetupIntentResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useCreateSetupIntentMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (params: { orgId: string; body: CreateSetupIntentRequest }) =>
|
|
8
|
+
client<CreateSetupIntentResponse>(
|
|
9
|
+
`/api/orgs/${encodeURIComponent(params.orgId)}/billing/payment-methods/setup-intent`,
|
|
10
|
+
{ method: 'POST', body: params.body },
|
|
11
|
+
),
|
|
12
|
+
})
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LoginRequest } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useLoginMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: LoginRequest) =>
|
|
8
|
+
client<void>('/api/auth/login', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MfaDisableRequest, MfaDisableResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useMfaDisableMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: MfaDisableRequest) =>
|
|
8
|
+
client<MfaDisableResponse>('/api/auth/mfa/disable', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MfaFinalizeRequest, MfaFinalizeResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useMfaFinalizeMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: MfaFinalizeRequest) =>
|
|
8
|
+
client<MfaFinalizeResponse>('/api/auth/mfa/finalize', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MfaRegenerateRecoveryCodesRequest, MfaRegenerateRecoveryCodesResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useMfaRegenerateRecoveryCodesMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: MfaRegenerateRecoveryCodesRequest) =>
|
|
8
|
+
client<MfaRegenerateRecoveryCodesResponse>('/api/auth/mfa/regenerate-recovery-codes', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MfaSetupResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useMfaSetupMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: () =>
|
|
8
|
+
client<MfaSetupResponse>('/api/auth/mfa/setup', { method: 'POST' }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MfaStepUpRequest, MfaStepUpResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useMfaStepUpMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: MfaStepUpRequest) =>
|
|
8
|
+
client<MfaStepUpResponse>('/api/auth/otp', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function useRemovePaymentMethodMutation() {
|
|
2
|
+
const client = useApiClient()
|
|
3
|
+
|
|
4
|
+
return useMutation({
|
|
5
|
+
mutation: (params: { orgId: string; paymentMethodId: string }) =>
|
|
6
|
+
client<void>(
|
|
7
|
+
`/api/orgs/${encodeURIComponent(params.orgId)}/billing/payment-methods/${encodeURIComponent(params.paymentMethodId)}`,
|
|
8
|
+
{ method: 'DELETE' },
|
|
9
|
+
),
|
|
10
|
+
})
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RequestLegalEntityChangeRequest } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useRequestLegalEntityChangeMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (params: { orgId: string; id: string; body: RequestLegalEntityChangeRequest }) =>
|
|
8
|
+
client<{ emails_status: 'sent' | 'failed' }>(
|
|
9
|
+
`/api/orgs/${encodeURIComponent(params.orgId)}/billing/legal-entities/${encodeURIComponent(params.id)}/change-request`,
|
|
10
|
+
{ method: 'POST', body: params.body },
|
|
11
|
+
),
|
|
12
|
+
})
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ForgotPasswordRequest } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useRequestPasswordResetMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: ForgotPasswordRequest) =>
|
|
8
|
+
client<void>('/api/auth/request-password-reset', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SubscriptionCancellationRequest, SubscriptionCancellationResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useRequestSubscriptionCancellationMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (params: { orgId: string; body: SubscriptionCancellationRequest }) =>
|
|
8
|
+
client<SubscriptionCancellationResponse>(
|
|
9
|
+
`/api/orgs/${encodeURIComponent(params.orgId)}/subscriptions/request-cancellation`,
|
|
10
|
+
{ method: 'POST', body: params.body },
|
|
11
|
+
),
|
|
12
|
+
})
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ResetPasswordRequest } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useResetPasswordMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: ResetPasswordRequest) =>
|
|
8
|
+
client<void>('/api/auth/reset-password', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SetPrimaryPaymentMethodRequest, SetPrimaryPaymentMethodResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useSetPrimaryPaymentMethodMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (params: { orgId: string; body: SetPrimaryPaymentMethodRequest }) =>
|
|
8
|
+
client<SetPrimaryPaymentMethodResponse>(
|
|
9
|
+
`/api/orgs/${encodeURIComponent(params.orgId)}/billing/payment-methods/primary`,
|
|
10
|
+
{ method: 'PATCH', body: params.body },
|
|
11
|
+
),
|
|
12
|
+
})
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { UpdateLegalEntityRequest, LegalEntityDetail } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useUpdateLegalEntityMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (params: { orgId: string; id: string; body: UpdateLegalEntityRequest }) =>
|
|
8
|
+
client<LegalEntityDetail>(
|
|
9
|
+
`/api/orgs/${encodeURIComponent(params.orgId)}/billing/legal-entities/${encodeURIComponent(params.id)}`,
|
|
10
|
+
{ method: 'PATCH', body: params.body },
|
|
11
|
+
),
|
|
12
|
+
})
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UpdateProfileRequest, UpdateProfileResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useUpdateProfileMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: UpdateProfileRequest) =>
|
|
8
|
+
client<UpdateProfileResponse>('/api/me', { method: 'PATCH', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BillingDocumentPdfResponse, BillingDocumentType } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export const billingDocumentPdfKeys = {
|
|
4
|
+
byId: (orgId: string, type: BillingDocumentType, id: string) =>
|
|
5
|
+
['billing', 'document-pdf', orgId, type, id] as const,
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function useBillingDocumentPdfQuery(
|
|
9
|
+
orgId: MaybeRefOrGetter<string>,
|
|
10
|
+
type: MaybeRefOrGetter<BillingDocumentType>,
|
|
11
|
+
id: MaybeRefOrGetter<string>,
|
|
12
|
+
) {
|
|
13
|
+
const client = useApiClient()
|
|
14
|
+
|
|
15
|
+
return useQuery({
|
|
16
|
+
key: () => billingDocumentPdfKeys.byId(toValue(orgId), toValue(type), toValue(id)),
|
|
17
|
+
query: () => client<BillingDocumentPdfResponse>(
|
|
18
|
+
`/api/orgs/${encodeURIComponent(toValue(orgId))}/billing/documents/${toValue(type)}/${encodeURIComponent(toValue(id))}/pdf`,
|
|
19
|
+
),
|
|
20
|
+
enabled: () => !!toValue(orgId) && !!toValue(id),
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ListBillingDocumentsResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export interface BillingDocumentsQueryParams {
|
|
4
|
+
legalEntityId?: string
|
|
5
|
+
customerId?: string
|
|
6
|
+
limit?: number
|
|
7
|
+
after?: string
|
|
8
|
+
before?: string
|
|
9
|
+
subscriptionIds?: string[]
|
|
10
|
+
type?: string
|
|
11
|
+
status?: string[]
|
|
12
|
+
search?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const billingDocumentsKeys = {
|
|
16
|
+
all: (orgId: string) => ['billing', 'documents', orgId] as const,
|
|
17
|
+
byOrg: (orgId: string, params?: BillingDocumentsQueryParams) =>
|
|
18
|
+
['billing', 'documents', orgId, JSON.stringify(params)] as const,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function useBillingDocumentsQuery(
|
|
22
|
+
orgId: MaybeRefOrGetter<string>,
|
|
23
|
+
params?: MaybeRefOrGetter<BillingDocumentsQueryParams | undefined>,
|
|
24
|
+
) {
|
|
25
|
+
const client = useApiClient()
|
|
26
|
+
|
|
27
|
+
return useQuery({
|
|
28
|
+
key: () => billingDocumentsKeys.byOrg(toValue(orgId), toValue(params)),
|
|
29
|
+
query: () => client<ListBillingDocumentsResponse>(
|
|
30
|
+
`/api/orgs/${encodeURIComponent(toValue(orgId))}/billing/documents`,
|
|
31
|
+
{ query: toValue(params) },
|
|
32
|
+
),
|
|
33
|
+
enabled: () => !!toValue(orgId),
|
|
34
|
+
})
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BillingOverviewResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export const billingOverviewKeys = {
|
|
4
|
+
byOrg: (orgId: string) => ['billing', 'overview', orgId] as const,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function useBillingOverviewQuery(orgId: MaybeRefOrGetter<string>) {
|
|
8
|
+
const client = useApiClient()
|
|
9
|
+
|
|
10
|
+
return useQuery({
|
|
11
|
+
key: () => billingOverviewKeys.byOrg(toValue(orgId)),
|
|
12
|
+
query: () => client<BillingOverviewResponse>(
|
|
13
|
+
`/api/orgs/${encodeURIComponent(toValue(orgId))}/billing`,
|
|
14
|
+
),
|
|
15
|
+
enabled: () => !!toValue(orgId),
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GetCrossSellingResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export const crossSellingKeys = {
|
|
4
|
+
all: () => ['cross-selling'] as const,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function useCrossSellingQuery() {
|
|
8
|
+
const client = useApiClient()
|
|
9
|
+
|
|
10
|
+
return useQuery({
|
|
11
|
+
key: crossSellingKeys.all,
|
|
12
|
+
query: () => client<GetCrossSellingResponse>('/api/me/cross-selling'),
|
|
13
|
+
})
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { LegalEntityDetail } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export const legalEntityKeys = {
|
|
4
|
+
byId: (orgId: string, id: string) => ['legal-entity', orgId, id] as const,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function useLegalEntityQuery(
|
|
8
|
+
orgId: MaybeRefOrGetter<string>,
|
|
9
|
+
id: MaybeRefOrGetter<string>,
|
|
10
|
+
) {
|
|
11
|
+
const client = useApiClient()
|
|
12
|
+
|
|
13
|
+
return useQuery({
|
|
14
|
+
key: () => legalEntityKeys.byId(toValue(orgId), toValue(id)),
|
|
15
|
+
query: () => client<LegalEntityDetail>(
|
|
16
|
+
`/api/orgs/${encodeURIComponent(toValue(orgId))}/billing/legal-entities/${encodeURIComponent(toValue(id))}`,
|
|
17
|
+
),
|
|
18
|
+
enabled: () => !!toValue(orgId) && !!toValue(id),
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { OrganizationContextResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export const organizationKeys = {
|
|
4
|
+
byId: (orgId: string) => ['organization', orgId] as const,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function useOrganizationQuery(orgId: MaybeRefOrGetter<string>) {
|
|
8
|
+
const client = useApiClient()
|
|
9
|
+
|
|
10
|
+
return useQuery({
|
|
11
|
+
key: () => organizationKeys.byId(toValue(orgId)),
|
|
12
|
+
query: () => client<OrganizationContextResponse>(
|
|
13
|
+
`/api/orgs/${encodeURIComponent(toValue(orgId))}`,
|
|
14
|
+
),
|
|
15
|
+
enabled: () => !!toValue(orgId),
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PermissionsResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export const permissionsKeys = {
|
|
4
|
+
all: () => ['permissions'] as const,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function usePermissionsQuery() {
|
|
8
|
+
const client = useApiClient()
|
|
9
|
+
|
|
10
|
+
return useQuery({
|
|
11
|
+
key: permissionsKeys.all,
|
|
12
|
+
query: () => client<PermissionsResponse>('/api/me/permissions'),
|
|
13
|
+
})
|
|
14
|
+
}
|