fauna-api 0.0.0-stage → 1.0.676

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 (171) hide show
  1. package/dist/brands.d.ts +2 -0
  2. package/dist/brands.js +2 -0
  3. package/dist/index.d.ts +64 -0
  4. package/dist/index.js +121 -0
  5. package/dist/src/ant/chat.d.ts +130 -0
  6. package/dist/src/ant/chat.js +467 -0
  7. package/dist/src/ant/format.d.ts +40 -0
  8. package/dist/src/ant/format.js +143 -0
  9. package/dist/src/ant/graph.d.ts +130 -0
  10. package/dist/src/ant/graph.js +449 -0
  11. package/dist/src/ant/index.d.ts +16 -0
  12. package/dist/src/ant/index.js +61 -0
  13. package/dist/src/ant/persona.d.ts +151 -0
  14. package/dist/src/ant/persona.js +136 -0
  15. package/dist/src/ant/timeline.d.ts +283 -0
  16. package/dist/src/ant/timeline.js +1025 -0
  17. package/dist/src/authentification.d.ts +45 -0
  18. package/dist/src/authentification.js +194 -0
  19. package/dist/src/billing.d.ts +135 -0
  20. package/dist/src/billing.js +128 -0
  21. package/dist/src/calendar.d.ts +83 -0
  22. package/dist/src/calendar.js +133 -0
  23. package/dist/src/chats.d.ts +113 -0
  24. package/dist/src/chats.js +100 -0
  25. package/dist/src/cicada/contacts.d.ts +31 -0
  26. package/dist/src/cicada/contacts.js +28 -0
  27. package/dist/src/cicada/conversations.d.ts +73 -0
  28. package/dist/src/cicada/conversations.js +236 -0
  29. package/dist/src/cicada/inboxes.d.ts +48 -0
  30. package/dist/src/cicada/inboxes.js +82 -0
  31. package/dist/src/cicada/index.d.ts +16 -0
  32. package/dist/src/cicada/index.js +61 -0
  33. package/dist/src/cicada/phone.d.ts +48 -0
  34. package/dist/src/cicada/phone.js +306 -0
  35. package/dist/src/drive.d.ts +80 -0
  36. package/dist/src/drive.js +472 -0
  37. package/dist/src/extensions/index.d.ts +4 -0
  38. package/dist/src/extensions/index.js +5 -0
  39. package/dist/src/extensions/web/index.d.ts +6 -0
  40. package/dist/src/extensions/web/index.js +7 -0
  41. package/dist/src/extensions/web/session.d.ts +106 -0
  42. package/dist/src/extensions/web/session.js +469 -0
  43. package/dist/src/extensions/web/tools.d.ts +13 -0
  44. package/dist/src/extensions/web/tools.js +72 -0
  45. package/dist/src/friends.d.ts +39 -0
  46. package/dist/src/friends.js +119 -0
  47. package/dist/src/groups.d.ts +82 -0
  48. package/dist/src/groups.js +269 -0
  49. package/dist/src/inbox.d.ts +11 -0
  50. package/dist/src/inbox.js +35 -0
  51. package/dist/src/integrations.d.ts +52 -0
  52. package/dist/src/integrations.js +205 -0
  53. package/dist/src/magpie/explorer.d.ts +14 -0
  54. package/dist/src/magpie/explorer.js +36 -0
  55. package/dist/src/magpie/index.d.ts +16 -0
  56. package/dist/src/magpie/index.js +61 -0
  57. package/dist/src/magpie/portfolio.d.ts +52 -0
  58. package/dist/src/magpie/portfolio.js +179 -0
  59. package/dist/src/magpie/quotes.d.ts +35 -0
  60. package/dist/src/magpie/quotes.js +47 -0
  61. package/dist/src/magpie/room.d.ts +61 -0
  62. package/dist/src/magpie/room.js +238 -0
  63. package/dist/src/maps.d.ts +159 -0
  64. package/dist/src/maps.js +171 -0
  65. package/dist/src/marmot/browser.d.ts +139 -0
  66. package/dist/src/marmot/browser.js +389 -0
  67. package/dist/src/marmot/index.d.ts +20 -0
  68. package/dist/src/marmot/index.js +65 -0
  69. package/dist/src/marmot/media.d.ts +56 -0
  70. package/dist/src/marmot/media.js +265 -0
  71. package/dist/src/marmot/research.d.ts +337 -0
  72. package/dist/src/marmot/research.js +1138 -0
  73. package/dist/src/marmot/scraper.d.ts +59 -0
  74. package/dist/src/marmot/scraper.js +94 -0
  75. package/dist/src/marmot/web.d.ts +402 -0
  76. package/dist/src/marmot/web.js +2586 -0
  77. package/dist/src/marmot/workspace.d.ts +81 -0
  78. package/dist/src/marmot/workspace.js +263 -0
  79. package/dist/src/parrot/agent.d.ts +53 -0
  80. package/dist/src/parrot/agent.js +93 -0
  81. package/dist/src/parrot/chat.d.ts +84 -0
  82. package/dist/src/parrot/chat.js +237 -0
  83. package/dist/src/parrot/format.d.ts +128 -0
  84. package/dist/src/parrot/format.js +639 -0
  85. package/dist/src/parrot/generative.d.ts +261 -0
  86. package/dist/src/parrot/generative.js +185 -0
  87. package/dist/src/parrot/index.d.ts +22 -0
  88. package/dist/src/parrot/index.js +67 -0
  89. package/dist/src/parrot/room.d.ts +225 -0
  90. package/dist/src/parrot/room.js +466 -0
  91. package/dist/src/parrot/routing.d.ts +90 -0
  92. package/dist/src/parrot/routing.js +78 -0
  93. package/dist/src/parrot/share.d.ts +126 -0
  94. package/dist/src/parrot/share.js +261 -0
  95. package/dist/src/parrot/socket.d.ts +41 -0
  96. package/dist/src/parrot/socket.js +478 -0
  97. package/dist/src/payments.d.ts +73 -0
  98. package/dist/src/payments.js +107 -0
  99. package/dist/src/private/cards.css +75 -0
  100. package/dist/src/rooms.d.ts +76 -0
  101. package/dist/src/rooms.js +168 -0
  102. package/dist/src/shared/schema.d.ts +24 -0
  103. package/dist/src/shared/schema.js +1 -0
  104. package/dist/src/shared/server.d.ts +65 -0
  105. package/dist/src/shared/server.js +302 -0
  106. package/dist/src/termite/environment.d.ts +110 -0
  107. package/dist/src/termite/environment.js +263 -0
  108. package/dist/src/termite/index.d.ts +14 -0
  109. package/dist/src/termite/index.js +59 -0
  110. package/dist/src/termite/os.d.ts +326 -0
  111. package/dist/src/termite/os.js +572 -0
  112. package/dist/src/termite/versioning.d.ts +94 -0
  113. package/dist/src/termite/versioning.js +217 -0
  114. package/dist/src/tickets.d.ts +43 -0
  115. package/dist/src/tickets.js +138 -0
  116. package/dist/src/travel.d.ts +85 -0
  117. package/dist/src/travel.js +44 -0
  118. package/dist/src/ui/authentification.d.ts +24 -0
  119. package/dist/src/ui/authentification.js +177 -0
  120. package/dist/src/ui/brands.css +11 -0
  121. package/dist/src/ui/brands.d.ts +7 -0
  122. package/dist/src/ui/brands.js +14 -0
  123. package/dist/src/ui/browser.d.ts +74 -0
  124. package/dist/src/ui/browser.js +470 -0
  125. package/dist/src/ui/chat.d.ts +183 -0
  126. package/dist/src/ui/chat.js +2379 -0
  127. package/dist/src/ui/chatPanel.d.ts +109 -0
  128. package/dist/src/ui/chatPanel.js +768 -0
  129. package/dist/src/ui/chatSequence.d.ts +36 -0
  130. package/dist/src/ui/chatSequence.js +42 -0
  131. package/dist/src/ui/crown.d.ts +19 -0
  132. package/dist/src/ui/crown.js +199 -0
  133. package/dist/src/ui/cursor.d.ts +73 -0
  134. package/dist/src/ui/cursor.js +175 -0
  135. package/dist/src/ui/device.d.ts +33 -0
  136. package/dist/src/ui/device.js +49 -0
  137. package/dist/src/ui/drive.d.ts +69 -0
  138. package/dist/src/ui/drive.js +1243 -0
  139. package/dist/src/ui/generative.d.ts +39 -0
  140. package/dist/src/ui/generative.js +313 -0
  141. package/dist/src/ui/hover.d.ts +6 -0
  142. package/dist/src/ui/hover.js +210 -0
  143. package/dist/src/ui/index.d.ts +42 -0
  144. package/dist/src/ui/index.js +87 -0
  145. package/dist/src/ui/integrations.d.ts +13 -0
  146. package/dist/src/ui/integrations.js +175 -0
  147. package/dist/src/ui/maps.d.ts +87 -0
  148. package/dist/src/ui/maps.js +547 -0
  149. package/dist/src/ui/roster.d.ts +32 -0
  150. package/dist/src/ui/roster.js +163 -0
  151. package/dist/src/ui/talk.d.ts +12 -0
  152. package/dist/src/ui/talk.js +560 -0
  153. package/dist/src/ui/tickets.d.ts +13 -0
  154. package/dist/src/ui/tickets.js +966 -0
  155. package/dist/src/ui/toast.d.ts +7 -0
  156. package/dist/src/ui/toast.js +258 -0
  157. package/dist/src/ui/tokenText.d.ts +18 -0
  158. package/dist/src/ui/tokenText.js +96 -0
  159. package/dist/src/ui/tokenized.d.ts +42 -0
  160. package/dist/src/ui/tokenized.js +622 -0
  161. package/dist/src/ui/ui.css +4763 -0
  162. package/dist/src/ui/view.d.ts +23 -0
  163. package/dist/src/ui/view.js +584 -0
  164. package/dist/src/view.d.ts +113 -0
  165. package/dist/src/view.js +386 -0
  166. package/dist/src/webhooks.d.ts +66 -0
  167. package/dist/src/webhooks.js +78 -0
  168. package/dist/ui.d.ts +1 -0
  169. package/dist/ui.js +1 -0
  170. package/package.json +89 -6
  171. package/README.md +0 -3
@@ -0,0 +1,205 @@
1
+ import { Fauna } from "../index.js";
2
+ export var Platform;
3
+ (function (Platform) {
4
+ Platform["GOOGLE"] = "GOOGLE";
5
+ Platform["SLACK"] = "SLACK";
6
+ Platform["DISCORD"] = "DISCORD";
7
+ Platform["TWILIO"] = "TWILIO";
8
+ Platform["MICROSOFT"] = "MICROSOFT";
9
+ Platform["WHATSAPP"] = "WHATSAPP";
10
+ })(Platform || (Platform = {}));
11
+ // One linked account on a platform. A user can link several accounts per
12
+ // platform (e.g. two gmails). Tokens stay server-side and are never exposed.
13
+ // Subclasses carry the platform specific surface (vars, calls).
14
+ export class Account {
15
+ constructor(authorization, platform, raw) {
16
+ Object.defineProperty(this, "authorization", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ Object.defineProperty(this, "platform", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
28
+ Object.defineProperty(this, "authorized", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: void 0
33
+ });
34
+ Object.defineProperty(this, "createdAt", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: void 0
39
+ });
40
+ Object.defineProperty(this, "id", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: void 0
45
+ });
46
+ this.authorization = authorization;
47
+ this.platform = platform;
48
+ this.authorized = raw.authorized;
49
+ this.createdAt = new Date(raw.createdAt);
50
+ this.id = raw.id;
51
+ }
52
+ async unlink() {
53
+ const response = await fetch(`${Fauna.getURL()}/integrations/accounts/${encodeURIComponent(this.id)}?platform=${encodeURIComponent(this.platform)}`, {
54
+ method: "DELETE",
55
+ headers: {
56
+ "Authorization": `Token ${this.authorization.token}`
57
+ }
58
+ });
59
+ if (!response.ok)
60
+ throw new Error(await response.text());
61
+ }
62
+ }
63
+ export class Google extends Account {
64
+ constructor(authorization, raw) {
65
+ super(authorization, Platform.GOOGLE, raw);
66
+ Object.defineProperty(this, "email", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
72
+ Object.defineProperty(this, "scopes", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: void 0
77
+ });
78
+ this.email = raw.email;
79
+ this.scopes = raw.scopes;
80
+ }
81
+ async getDemographics() {
82
+ const response = await fetch(`${Fauna.getURL()}/integrations/google/youtube/demographics`, {
83
+ method: "POST",
84
+ headers: {
85
+ "Content-Type": "application/json",
86
+ "Authorization": `Token ${this.authorization.token}`
87
+ },
88
+ body: JSON.stringify({ accountId: this.id })
89
+ });
90
+ if (!response.ok)
91
+ throw new Error(await response.text());
92
+ return await response.json();
93
+ }
94
+ }
95
+ export class Slack extends Account {
96
+ constructor(authorization, raw) {
97
+ super(authorization, Platform.SLACK, raw);
98
+ Object.defineProperty(this, "email", {
99
+ enumerable: true,
100
+ configurable: true,
101
+ writable: true,
102
+ value: void 0
103
+ });
104
+ Object.defineProperty(this, "scopes", {
105
+ enumerable: true,
106
+ configurable: true,
107
+ writable: true,
108
+ value: void 0
109
+ });
110
+ this.email = raw.email;
111
+ this.scopes = raw.scopes;
112
+ }
113
+ }
114
+ export class Discord extends Account {
115
+ constructor(authorization, raw) {
116
+ super(authorization, Platform.DISCORD, raw);
117
+ Object.defineProperty(this, "handle", {
118
+ enumerable: true,
119
+ configurable: true,
120
+ writable: true,
121
+ value: void 0
122
+ });
123
+ this.handle = raw.handle;
124
+ }
125
+ }
126
+ export class Twilio extends Account {
127
+ constructor(authorization, raw) {
128
+ super(authorization, Platform.TWILIO, raw);
129
+ Object.defineProperty(this, "phone", {
130
+ enumerable: true,
131
+ configurable: true,
132
+ writable: true,
133
+ value: void 0
134
+ });
135
+ this.phone = raw.phone;
136
+ }
137
+ }
138
+ export class Microsoft extends Account {
139
+ constructor(authorization, raw) {
140
+ super(authorization, Platform.MICROSOFT, raw);
141
+ Object.defineProperty(this, "email", {
142
+ enumerable: true,
143
+ configurable: true,
144
+ writable: true,
145
+ value: void 0
146
+ });
147
+ Object.defineProperty(this, "scopes", {
148
+ enumerable: true,
149
+ configurable: true,
150
+ writable: true,
151
+ value: void 0
152
+ });
153
+ this.email = raw.email;
154
+ this.scopes = raw.scopes;
155
+ }
156
+ }
157
+ export class WhatsApp extends Account {
158
+ constructor(authorization, raw) {
159
+ super(authorization, Platform.WHATSAPP, raw);
160
+ Object.defineProperty(this, "phone", {
161
+ enumerable: true,
162
+ configurable: true,
163
+ writable: true,
164
+ value: void 0
165
+ });
166
+ this.phone = raw.phone;
167
+ }
168
+ }
169
+ function wrapAccount(authorization, platform, raw) {
170
+ switch (platform) {
171
+ case Platform.GOOGLE: return new Google(authorization, raw);
172
+ case Platform.SLACK: return new Slack(authorization, raw);
173
+ case Platform.DISCORD: return new Discord(authorization, raw);
174
+ case Platform.TWILIO: return new Twilio(authorization, raw);
175
+ case Platform.MICROSOFT: return new Microsoft(authorization, raw);
176
+ case Platform.WHATSAPP: return new WhatsApp(authorization, raw);
177
+ }
178
+ }
179
+ export async function linkPlatform(credentials, integration) {
180
+ const response = await fetch(`${Fauna.getURL()}/integrations/link`, {
181
+ method: "POST",
182
+ headers: {
183
+ "Content-Type": "application/json",
184
+ "Authorization": `Token ${credentials.token}`
185
+ },
186
+ body: JSON.stringify({ integration })
187
+ });
188
+ if (!response.ok) {
189
+ return null;
190
+ }
191
+ const { url } = await response.json();
192
+ return window.open(url, "_blank", "width=500,height=600");
193
+ }
194
+ export async function getAccounts(credentials) {
195
+ const response = await fetch(`${Fauna.getURL()}/integrations/accounts`, {
196
+ method: "GET",
197
+ headers: {
198
+ "Authorization": `Token ${credentials.token}`
199
+ }
200
+ });
201
+ if (!response.ok)
202
+ throw new Error(await response.text());
203
+ const json = await response.json();
204
+ return json.map((raw) => wrapAccount(credentials, raw.platform, raw));
205
+ }
@@ -0,0 +1,14 @@
1
+ import { Credentials, ApiKey } from "../authentification.js";
2
+ import { Asset } from "./portfolio.js";
3
+ export { ExplorerRoom } from "./room.js";
4
+ export type Trend = [number, number, number, number];
5
+ export type Explorer = {
6
+ ticker: string;
7
+ asset: Asset;
8
+ trends: Trend[];
9
+ horizontals: number[];
10
+ notifications: number[];
11
+ };
12
+ export declare function listExplorers(authorization: Credentials | ApiKey): Promise<Explorer[]>;
13
+ export declare function getExplorer(authorization: Credentials | ApiKey, asset: Asset, ticker: string): Promise<Explorer>;
14
+ export declare function setExplorer(authorization: Credentials | ApiKey, explorer: Explorer): Promise<void>;
@@ -0,0 +1,36 @@
1
+ import { Magpie } from "./index.js";
2
+ export { ExplorerRoom } from "./room.js";
3
+ export async function listExplorers(authorization) {
4
+ const response = await fetch(`${Magpie.getURL()}/magpie/explorers`, {
5
+ method: 'GET',
6
+ headers: {
7
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
8
+ }
9
+ });
10
+ if (!response.ok)
11
+ throw new Error(await response.text());
12
+ return await response.json();
13
+ }
14
+ export async function getExplorer(authorization, asset, ticker) {
15
+ const response = await fetch(`${Magpie.getURL()}/magpie/explorer/${encodeURIComponent(asset)}/${encodeURIComponent(ticker)}`, {
16
+ method: 'GET',
17
+ headers: {
18
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
19
+ }
20
+ });
21
+ if (!response.ok)
22
+ throw new Error(await response.text());
23
+ return await response.json();
24
+ }
25
+ export async function setExplorer(authorization, explorer) {
26
+ const response = await fetch(`${Magpie.getURL()}/magpie/explorer`, {
27
+ method: 'PUT',
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
31
+ },
32
+ body: JSON.stringify({ explorer })
33
+ });
34
+ if (!response.ok)
35
+ throw new Error(await response.text());
36
+ }
@@ -0,0 +1,16 @@
1
+ import * as PortfolioAPI from "./portfolio.js";
2
+ import * as QuotesAPI from "./quotes.js";
3
+ import * as ExplorerAPI from "./explorer.js";
4
+ import * as RoomAPI from "./room.js";
5
+ export declare namespace Magpie {
6
+ function setRoute(route: string): void;
7
+ function getIP(): string;
8
+ function getPort(): number;
9
+ function getRoute(): string;
10
+ function getURL(): string;
11
+ function ping(): Promise<number>;
12
+ export import Portfolio = PortfolioAPI;
13
+ export import Quotes = QuotesAPI;
14
+ export import Explorer = ExplorerAPI;
15
+ export import Room = RoomAPI;
16
+ }
@@ -0,0 +1,61 @@
1
+ import * as PortfolioAPI from "./portfolio.js";
2
+ import * as QuotesAPI from "./quotes.js";
3
+ import * as ExplorerAPI from "./explorer.js";
4
+ import * as RoomAPI from "./room.js";
5
+ export var Magpie;
6
+ (function (Magpie) {
7
+ var PREFIX = 'https://';
8
+ var IP = 'api.faunakit.com';
9
+ var PORT = 443;
10
+ function setRoute(route) {
11
+ const parts_0 = route.split('//');
12
+ if (parts_0.length > 1) {
13
+ PREFIX = parts_0[0] + '//';
14
+ const parts_1 = parts_0[1].split(':');
15
+ if (parts_1.length > 1) {
16
+ IP = parts_1[0];
17
+ PORT = Number(parts_1[1]);
18
+ }
19
+ else {
20
+ IP = parts_1[0];
21
+ }
22
+ }
23
+ else {
24
+ const parts_1 = parts_0[0].split(':');
25
+ if (parts_1.length > 1) {
26
+ IP = parts_1[0];
27
+ PORT = Number(parts_1[1]);
28
+ }
29
+ else {
30
+ IP = parts_1[0];
31
+ }
32
+ }
33
+ }
34
+ Magpie.setRoute = setRoute;
35
+ function getIP() {
36
+ return IP;
37
+ }
38
+ Magpie.getIP = getIP;
39
+ function getPort() {
40
+ return PORT;
41
+ }
42
+ Magpie.getPort = getPort;
43
+ function getRoute() {
44
+ return IP + ':' + PORT;
45
+ }
46
+ Magpie.getRoute = getRoute;
47
+ function getURL() {
48
+ return PREFIX + IP + ':' + PORT;
49
+ }
50
+ Magpie.getURL = getURL;
51
+ async function ping() {
52
+ const start = Date.now();
53
+ await fetch(`${getURL()}/`);
54
+ return Date.now() - start;
55
+ }
56
+ Magpie.ping = ping;
57
+ Magpie.Portfolio = PortfolioAPI;
58
+ Magpie.Quotes = QuotesAPI;
59
+ Magpie.Explorer = ExplorerAPI;
60
+ Magpie.Room = RoomAPI;
61
+ })(Magpie || (Magpie = {}));
@@ -0,0 +1,52 @@
1
+ import { Credentials, ApiKey } from "../authentification.js";
2
+ import { Group } from "../groups.js";
3
+ export { PortfolioRoom } from "./room.js";
4
+ export type { PortfolioEntry } from "./room.js";
5
+ export declare enum Asset {
6
+ EQUITY = "EQUITY",
7
+ CRYPTO = "CRYPTO",
8
+ MONEY_MARKET = "MONEY_MARKET",
9
+ OTHER = "OTHER"
10
+ }
11
+ export type Position = {
12
+ id: string;
13
+ asset: Asset;
14
+ symbol: string;
15
+ name: string;
16
+ quantity: number;
17
+ costBasis: number;
18
+ date: Date;
19
+ /** HTTPS URL Magpie pulls for OTHER quotes. Ignored for other assets. */
20
+ source?: string;
21
+ };
22
+ export type Holding = {
23
+ id: string;
24
+ name: string;
25
+ estimates: {
26
+ value: number;
27
+ date: Date;
28
+ }[];
29
+ };
30
+ export type Portfolio = {
31
+ id: string;
32
+ name: string;
33
+ profile: (Position | Holding)[];
34
+ created: Date;
35
+ lastModified: Date;
36
+ };
37
+ export type GroupOpts = {
38
+ group?: Group;
39
+ };
40
+ export declare function getPortfolios(authorization: Credentials | ApiKey, opts?: GroupOpts): Promise<Portfolio[]>;
41
+ export declare function getPortfolio(authorization: Credentials | ApiKey, portfolioId: string, opts?: GroupOpts): Promise<Portfolio>;
42
+ export declare function createPortfolio(authorization: Credentials | ApiKey, name: string, opts?: GroupOpts): Promise<string>;
43
+ export declare function removePortfolio(authorization: Credentials | ApiKey, portfolioId: string, opts?: GroupOpts): Promise<void>;
44
+ export declare function addPosition(authorization: Credentials | ApiKey, portfolioId: string, position: Omit<Position, 'id'>, opts?: GroupOpts): Promise<string>;
45
+ export declare function updatePosition(authorization: Credentials | ApiKey, portfolioId: string, positionId: string, updates: Partial<Position>, opts?: GroupOpts): Promise<void>;
46
+ export declare function removePosition(authorization: Credentials | ApiKey, portfolioId: string, positionId: string, opts?: GroupOpts): Promise<void>;
47
+ export declare function addHolding(authorization: Credentials | ApiKey, portfolioId: string, holding: Omit<Holding, 'id'>, opts?: GroupOpts): Promise<string>;
48
+ export declare function addEstimate(authorization: Credentials | ApiKey, portfolioId: string, holdingId: string, estimate: {
49
+ value: number;
50
+ date: Date;
51
+ }, opts?: GroupOpts): Promise<void>;
52
+ export declare function removeHolding(authorization: Credentials | ApiKey, portfolioId: string, holdingId: string, opts?: GroupOpts): Promise<void>;
@@ -0,0 +1,179 @@
1
+ import { Magpie } from "./index.js";
2
+ export { PortfolioRoom } from "./room.js";
3
+ export var Asset;
4
+ (function (Asset) {
5
+ Asset["EQUITY"] = "EQUITY";
6
+ Asset["CRYPTO"] = "CRYPTO";
7
+ Asset["MONEY_MARKET"] = "MONEY_MARKET";
8
+ Asset["OTHER"] = "OTHER";
9
+ })(Asset || (Asset = {}));
10
+ function wrapPosition(raw) {
11
+ return {
12
+ ...raw,
13
+ date: new Date(raw.date),
14
+ source: typeof raw.source === 'string' && raw.source ? raw.source : undefined,
15
+ };
16
+ }
17
+ function wrapHolding(raw) {
18
+ return {
19
+ ...raw,
20
+ estimates: (raw.estimates ?? []).map((e) => ({ value: e.value, date: new Date(e.date) }))
21
+ };
22
+ }
23
+ function wrapEntry(raw) {
24
+ if ('asset' in raw)
25
+ return wrapPosition(raw);
26
+ return wrapHolding(raw);
27
+ }
28
+ function wrapPortfolio(raw) {
29
+ return {
30
+ ...raw,
31
+ profile: (raw.profile ?? []).map(wrapEntry),
32
+ created: new Date(raw.created),
33
+ lastModified: new Date(raw.lastModified)
34
+ };
35
+ }
36
+ export async function getPortfolios(authorization, opts) {
37
+ const response = await fetch(`${Magpie.getURL()}/magpie/portfolios`, {
38
+ method: 'GET',
39
+ headers: {
40
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
41
+ ...(opts?.group ? { Group: opts.group.id } : {}),
42
+ },
43
+ });
44
+ if (!response.ok)
45
+ throw new Error(await response.text());
46
+ const json = await response.json();
47
+ return json.map(wrapPortfolio);
48
+ }
49
+ export async function getPortfolio(authorization, portfolioId, opts) {
50
+ const response = await fetch(`${Magpie.getURL()}/magpie/portfolios/${encodeURIComponent(portfolioId)}`, {
51
+ method: 'GET',
52
+ headers: {
53
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
54
+ ...(opts?.group ? { Group: opts.group.id } : {}),
55
+ },
56
+ });
57
+ if (!response.ok)
58
+ throw new Error(await response.text());
59
+ return wrapPortfolio(await response.json());
60
+ }
61
+ export async function createPortfolio(authorization, name, opts) {
62
+ const response = await fetch(`${Magpie.getURL()}/magpie/portfolios`, {
63
+ method: 'POST',
64
+ headers: {
65
+ 'Content-Type': 'application/json',
66
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
67
+ ...(opts?.group ? { Group: opts.group.id } : {}),
68
+ },
69
+ body: JSON.stringify({ name })
70
+ });
71
+ if (!response.ok)
72
+ throw new Error(await response.text());
73
+ const json = await response.json();
74
+ return json.id;
75
+ }
76
+ export async function removePortfolio(authorization, portfolioId, opts) {
77
+ const response = await fetch(`${Magpie.getURL()}/magpie/portfolios/${encodeURIComponent(portfolioId)}`, {
78
+ method: 'DELETE',
79
+ headers: {
80
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
81
+ ...(opts?.group ? { Group: opts.group.id } : {}),
82
+ },
83
+ });
84
+ if (!response.ok)
85
+ throw new Error(await response.text());
86
+ }
87
+ export async function addPosition(authorization, portfolioId, position, opts) {
88
+ const response = await fetch(`${Magpie.getURL()}/magpie/portfolios/${encodeURIComponent(portfolioId)}/positions`, {
89
+ method: 'POST',
90
+ headers: {
91
+ 'Content-Type': 'application/json',
92
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
93
+ ...(opts?.group ? { Group: opts.group.id } : {}),
94
+ },
95
+ body: JSON.stringify({
96
+ position: {
97
+ ...position,
98
+ date: position.date.toISOString()
99
+ }
100
+ })
101
+ });
102
+ if (!response.ok)
103
+ throw new Error(await response.text());
104
+ const json = await response.json();
105
+ return json.id;
106
+ }
107
+ export async function updatePosition(authorization, portfolioId, positionId, updates, opts) {
108
+ const serialized = { ...updates };
109
+ if (updates.date)
110
+ serialized.date = updates.date.toISOString();
111
+ const response = await fetch(`${Magpie.getURL()}/magpie/portfolios/${encodeURIComponent(portfolioId)}/positions/${encodeURIComponent(positionId)}`, {
112
+ method: 'PATCH',
113
+ headers: {
114
+ 'Content-Type': 'application/json',
115
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
116
+ ...(opts?.group ? { Group: opts.group.id } : {}),
117
+ },
118
+ body: JSON.stringify({ updates: serialized })
119
+ });
120
+ if (!response.ok)
121
+ throw new Error(await response.text());
122
+ }
123
+ export async function removePosition(authorization, portfolioId, positionId, opts) {
124
+ const response = await fetch(`${Magpie.getURL()}/magpie/portfolios/${encodeURIComponent(portfolioId)}/positions/${encodeURIComponent(positionId)}`, {
125
+ method: 'DELETE',
126
+ headers: {
127
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
128
+ ...(opts?.group ? { Group: opts.group.id } : {}),
129
+ },
130
+ });
131
+ if (!response.ok)
132
+ throw new Error(await response.text());
133
+ }
134
+ export async function addHolding(authorization, portfolioId, holding, opts) {
135
+ const response = await fetch(`${Magpie.getURL()}/magpie/portfolios/${encodeURIComponent(portfolioId)}/holdings`, {
136
+ method: 'POST',
137
+ headers: {
138
+ 'Content-Type': 'application/json',
139
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
140
+ ...(opts?.group ? { Group: opts.group.id } : {}),
141
+ },
142
+ body: JSON.stringify({
143
+ holding: {
144
+ ...holding,
145
+ estimates: holding.estimates.map(e => ({ value: e.value, date: e.date.toISOString() }))
146
+ }
147
+ })
148
+ });
149
+ if (!response.ok)
150
+ throw new Error(await response.text());
151
+ const json = await response.json();
152
+ return json.id;
153
+ }
154
+ export async function addEstimate(authorization, portfolioId, holdingId, estimate, opts) {
155
+ const response = await fetch(`${Magpie.getURL()}/magpie/portfolios/${encodeURIComponent(portfolioId)}/holdings/${encodeURIComponent(holdingId)}/estimates`, {
156
+ method: 'POST',
157
+ headers: {
158
+ 'Content-Type': 'application/json',
159
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
160
+ ...(opts?.group ? { Group: opts.group.id } : {}),
161
+ },
162
+ body: JSON.stringify({
163
+ estimate: { value: estimate.value, date: estimate.date.toISOString() }
164
+ })
165
+ });
166
+ if (!response.ok)
167
+ throw new Error(await response.text());
168
+ }
169
+ export async function removeHolding(authorization, portfolioId, holdingId, opts) {
170
+ const response = await fetch(`${Magpie.getURL()}/magpie/portfolios/${encodeURIComponent(portfolioId)}/holdings/${encodeURIComponent(holdingId)}`, {
171
+ method: 'DELETE',
172
+ headers: {
173
+ 'Authorization': 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
174
+ ...(opts?.group ? { Group: opts.group.id } : {}),
175
+ },
176
+ });
177
+ if (!response.ok)
178
+ throw new Error(await response.text());
179
+ }
@@ -0,0 +1,35 @@
1
+ import { Credentials, ApiKey } from "../authentification.js";
2
+ import { Asset } from "./portfolio.js";
3
+ export type Quote = {
4
+ symbol: string;
5
+ asset: Asset;
6
+ price: number;
7
+ change: number;
8
+ changePercent: number;
9
+ marketCap?: number;
10
+ volume?: number;
11
+ timestamp: Date;
12
+ };
13
+ export type Price = {
14
+ date: Date;
15
+ open: number;
16
+ high: number;
17
+ low: number;
18
+ close: number;
19
+ volume: number;
20
+ };
21
+ export type SearchResult = {
22
+ symbol: string;
23
+ name: string;
24
+ asset: Asset;
25
+ exchange?: string;
26
+ };
27
+ export type Interval = '1d' | '1h' | '1wk' | '1mo';
28
+ export type SourceOpts = {
29
+ source?: string;
30
+ };
31
+ export declare function quoteAsset(authorization: Credentials | ApiKey, asset: Asset, symbol: string, opts?: SourceOpts): Promise<Quote>;
32
+ export declare function priceAsset(authorization: Credentials | ApiKey, asset: Asset, symbol: string, start: Date, end: Date, interval: Interval, opts?: SourceOpts): Promise<Price[]>;
33
+ export declare function quoteSource(authorization: Credentials | ApiKey, url: string): Promise<Quote>;
34
+ export declare function priceSource(authorization: Credentials | ApiKey, url: string, start: Date, end: Date, interval: Interval): Promise<Price[]>;
35
+ export declare function search(authorization: Credentials | ApiKey, asset: Asset, query: string): Promise<SearchResult[]>;
@@ -0,0 +1,47 @@
1
+ import { Magpie } from "./index.js";
2
+ import { Asset } from "./portfolio.js";
3
+ function wrapQuote(raw) {
4
+ return { ...raw, timestamp: new Date(raw.timestamp) };
5
+ }
6
+ function wrapPrice(raw) {
7
+ return { ...raw, date: new Date(raw.date) };
8
+ }
9
+ export async function quoteAsset(authorization, asset, symbol, opts) {
10
+ const params = new URLSearchParams();
11
+ if (opts?.source)
12
+ params.set('source', opts.source);
13
+ const query = params.toString();
14
+ const response = await fetch(`${Magpie.getURL()}/magpie/quote/${encodeURIComponent(asset)}/${encodeURIComponent(symbol)}${query ? `?${query}` : ''}`, { method: 'GET', headers: { Authorization: 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}` } });
15
+ if (!response.ok)
16
+ throw new Error(await response.text());
17
+ return wrapQuote(await response.json());
18
+ }
19
+ export async function priceAsset(authorization, asset, symbol, start, end, interval, opts) {
20
+ const params = new URLSearchParams({
21
+ start: start.toISOString(),
22
+ end: end.toISOString(),
23
+ interval,
24
+ });
25
+ if (opts?.source)
26
+ params.set('source', opts.source);
27
+ const response = await fetch(`${Magpie.getURL()}/magpie/price/${encodeURIComponent(asset)}/${encodeURIComponent(symbol)}?${params}`, { method: 'GET', headers: { Authorization: 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}` } });
28
+ if (!response.ok)
29
+ throw new Error(await response.text());
30
+ const json = await response.json();
31
+ return json.map(wrapPrice);
32
+ }
33
+ export async function quoteSource(authorization, url) {
34
+ return quoteAsset(authorization, Asset.OTHER, '_', { source: url });
35
+ }
36
+ export async function priceSource(authorization, url, start, end, interval) {
37
+ return priceAsset(authorization, Asset.OTHER, '_', start, end, interval, { source: url });
38
+ }
39
+ export async function search(authorization, asset, query) {
40
+ const response = await fetch(`${Magpie.getURL()}/magpie/search/${encodeURIComponent(asset)}?query=${encodeURIComponent(query)}`, {
41
+ method: 'GET',
42
+ headers: { Authorization: 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}` },
43
+ });
44
+ if (!response.ok)
45
+ throw new Error(await response.text());
46
+ return await response.json();
47
+ }