@cranberry-money/shared-services 1.8.0 → 1.9.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.
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export * as AuthService from './services/auth';
17
17
  export * as CashAccountsService from './services/cash_accounts';
18
18
  export * as InstrumentsService from './services/instruments';
19
19
  export * as PortfoliosService from './services/portfolios';
20
+ export * as PortfolioTemplatesService from './services/portfolio_templates';
20
21
  export * as UsersService from './services/users';
21
22
  export * as TradesService from './services/trades';
22
23
  export * as WithdrawalsService from './services/withdrawals';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAG3C,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAGrB,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAG5C,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,WAAW,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,kBAAkB,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,iBAAiB,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAC;AAC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oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ export * as AuthService from './services/auth';
21
21
  export * as CashAccountsService from './services/cash_accounts';
22
22
  export * as InstrumentsService from './services/instruments';
23
23
  export * as PortfoliosService from './services/portfolios';
24
+ export * as PortfolioTemplatesService from './services/portfolio_templates';
24
25
  export * as UsersService from './services/users';
25
26
  export * as TradesService from './services/trades';
26
27
  export * as WithdrawalsService from './services/withdrawals';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Portfolio templates API constants
3
+ */
4
+ export declare const API_ENDPOINTS: {
5
+ readonly PORTFOLIO_TEMPLATES: "/api/portfolio-templates/";
6
+ readonly PORTFOLIO_TEMPLATES_RECOMMENDED: "/api/portfolio-templates/recommended/";
7
+ };
8
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/services/portfolio_templates/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,eAAO,MAAM,aAAa;;;CAGhB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Portfolio templates API constants
3
+ */
4
+ // API Endpoints
5
+ export const API_ENDPOINTS = {
6
+ PORTFOLIO_TEMPLATES: '/api/portfolio-templates/',
7
+ PORTFOLIO_TEMPLATES_RECOMMENDED: '/api/portfolio-templates/recommended/',
8
+ };
@@ -0,0 +1,5 @@
1
+ export * from './constants';
2
+ export * from './types';
3
+ export * from './service';
4
+ export * from './utils';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/portfolio_templates/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,5 @@
1
+ // Portfolio templates domain exports
2
+ export * from './constants';
3
+ export * from './types';
4
+ export * from './service';
5
+ export * from './utils';
@@ -0,0 +1,6 @@
1
+ import type { PortfolioTemplate, TargetAssetAllocation, ApplyTemplateResponse, PaginatedPortfolioTemplates } from './types';
2
+ export declare const getPortfolioTemplates: () => Promise<import("axios").AxiosResponse<PaginatedPortfolioTemplates, any>>;
3
+ export declare const getRecommendedPortfolioTemplate: () => Promise<import("axios").AxiosResponse<PortfolioTemplate, any>>;
4
+ export declare const getPortfolioTemplateAllocations: (templateUuid: string) => Promise<import("axios").AxiosResponse<TargetAssetAllocation[], any>>;
5
+ export declare const applyPortfolioTemplate: (templateUuid: string) => Promise<import("axios").AxiosResponse<ApplyTemplateResponse, any>>;
6
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/services/portfolio_templates/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,qBAAqB,gFAEjC,CAAC;AAEF,eAAO,MAAM,+BAA+B,sEAE3C,CAAC;AAEF,eAAO,MAAM,+BAA+B,GAAI,cAAc,MAAM,yEAEnE,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,cAAc,MAAM,uEAE1D,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { webApiClient } from '../../api/apiClient';
2
+ import { API_ENDPOINTS } from './constants';
3
+ export const getPortfolioTemplates = () => {
4
+ return webApiClient.get(API_ENDPOINTS.PORTFOLIO_TEMPLATES);
5
+ };
6
+ export const getRecommendedPortfolioTemplate = () => {
7
+ return webApiClient.get(API_ENDPOINTS.PORTFOLIO_TEMPLATES_RECOMMENDED);
8
+ };
9
+ export const getPortfolioTemplateAllocations = (templateUuid) => {
10
+ return webApiClient.get(`${API_ENDPOINTS.PORTFOLIO_TEMPLATES}${templateUuid}/allocations/`);
11
+ };
12
+ export const applyPortfolioTemplate = (templateUuid) => {
13
+ return webApiClient.post(`${API_ENDPOINTS.PORTFOLIO_TEMPLATES}${templateUuid}/apply/`, {});
14
+ };
@@ -0,0 +1,49 @@
1
+ import type { PaginatedResponse } from '../../api/types';
2
+ export interface Instrument {
3
+ uuid: string;
4
+ symbol: string;
5
+ name: string;
6
+ instrumentType: string;
7
+ sector?: string;
8
+ stockExchange?: string;
9
+ }
10
+ export interface Portfolio {
11
+ uuid: string;
12
+ name: string;
13
+ description: string;
14
+ isActive: boolean;
15
+ createdAt?: string;
16
+ updatedAt?: string;
17
+ }
18
+ export interface PortfolioTemplate {
19
+ uuid: string;
20
+ name: string;
21
+ description: string;
22
+ isActive: boolean;
23
+ riskLevel: string;
24
+ createdAt?: string;
25
+ updatedAt?: string;
26
+ }
27
+ export interface TargetAssetAllocation {
28
+ uuid: string;
29
+ instrument: Instrument;
30
+ percentage: string;
31
+ }
32
+ export interface AssetAllocation {
33
+ instrument: {
34
+ symbol: string;
35
+ name: string;
36
+ };
37
+ percentage: string;
38
+ }
39
+ /**
40
+ * Response when applying a portfolio template
41
+ */
42
+ export interface ApplyTemplateResponse {
43
+ success: boolean;
44
+ message: string;
45
+ portfolio: Portfolio;
46
+ allocations: AssetAllocation[];
47
+ }
48
+ export type PaginatedPortfolioTemplates = PaginatedResponse<PortfolioTemplate>;
49
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/portfolio_templates/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,eAAe,EAAE,CAAC;CAChC;AAGD,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare const calculateTotalAllocation: (allocations: {
2
+ percentage: string;
3
+ }[]) => number;
4
+ export declare const validateAllocationPercentages: (allocations: {
5
+ percentage: string;
6
+ }[]) => boolean;
7
+ export declare const formatRiskLevel: (riskLevel: string) => string;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/portfolio_templates/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,wBAAwB,GAAI,aAAa;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,EAAE,KAAG,MAIhF,CAAC;AAEF,eAAO,MAAM,6BAA6B,GAAI,aAAa;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,EAAE,KAAG,OAGrF,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,KAAG,MAEnD,CAAC"}
@@ -0,0 +1,13 @@
1
+ // Portfolio template utilities and helper functions
2
+ export const calculateTotalAllocation = (allocations) => {
3
+ return allocations.reduce((total, allocation) => {
4
+ return total + parseFloat(allocation.percentage || '0');
5
+ }, 0);
6
+ };
7
+ export const validateAllocationPercentages = (allocations) => {
8
+ const total = calculateTotalAllocation(allocations);
9
+ return Math.abs(total - 100) < 0.01; // Allow for small floating point differences
10
+ };
11
+ export const formatRiskLevel = (riskLevel) => {
12
+ return riskLevel.charAt(0).toUpperCase() + riskLevel.slice(1).toLowerCase();
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cranberry-money/shared-services",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Shared API services and client for MyPortfolio platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",