@distilled.cloud/questrade 1.0.0-rc.20 → 1.0.0-rc.22

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/src/index.ts CHANGED
@@ -22,7 +22,7 @@
22
22
  *
23
23
  * program.pipe(
24
24
  * Effect.provide(
25
- * Layer.mergeAll(FetchHttpClient.layer, Questrade.CredentialsFromEnv, Questrade.QuestradeProtocol),
25
+ * Questrade.CredentialsFromEnv.pipe(Layer.provideMerge(FetchHttpClient.layer)),
26
26
  * ),
27
27
  * Effect.runPromise,
28
28
  * );
package/src/protocol.ts CHANGED
@@ -1,7 +1,5 @@
1
- import type * as API from "@distilled.cloud/core/api";
2
- import type { ConfigError, InvalidInput } from "@distilled.cloud/core/errors";
3
- import { makeRestProtocol, unknownErrorProps } from "@distilled.cloud/core/protocol-rest";
4
- import type { SdkError } from "@distilled.cloud/core/sdk-error";
1
+ import type { ErrorOf } from "@distilled.cloud/core/protocol";
2
+ import { restProtocol, unknownErrorProps } from "@distilled.cloud/core/protocol-rest";
5
3
  /**
6
4
  * Questrade protocol -- the shared REST protocol with Questrade's auth.
7
5
  *
@@ -17,32 +15,30 @@ import type { SdkError } from "@distilled.cloud/core/sdk-error";
17
15
  */
18
16
  import * as Effect from "effect/Effect";
19
17
  import type * as HttpClient from "effect/http/HttpClient";
20
- import type * as HttpClientError from "effect/http/HttpClientError";
21
- import type * as Layer from "effect/Layer";
22
18
  import * as Redacted from "effect/Redacted";
23
- import { Credentials, type Config } from "./credentials.ts";
24
- import { QuestradeParseError, UnknownQuestradeError, type DefaultErrors } from "./errors.ts";
19
+ import { Credentials } from "./credentials.ts";
20
+ import {
21
+ QuestradeParseError,
22
+ UnknownQuestradeError,
23
+ type QuestradeServiceError,
24
+ } from "./errors.ts";
25
25
 
26
26
  /**
27
- * Error channel shared by every generated Questrade operation. Generated
28
- * service files annotate operations with `API.OperationMethod<I, O,
29
- * QuestradeOpError, QuestradeOpContext>` explicitly so the compiler never
30
- * infers these back out of the schema generics.
27
+ * What every generated Questrade operation fails with besides its own errors:
28
+ * the service's errors, the protocol's, and what resolving the credentials
29
+ * fails with. Generated service files annotate operations with
30
+ * `API.OperationMethod<I, O, QuestradeOpError, QuestradeOpContext>` explicitly
31
+ * so the compiler never infers these back out of the schema generics.
31
32
  */
32
- export type QuestradeOpError =
33
- | DefaultErrors
34
- | ConfigError
35
- | HttpClientError.HttpClientError
36
- | InvalidInput
37
- | SdkError;
33
+ export type QuestradeOpError = QuestradeServiceError | ErrorOf<typeof QuestradeProtocol>;
38
34
 
39
35
  /** Context (requirements) shared by every generated Questrade operation. */
40
36
  export type QuestradeOpContext = Credentials | HttpClient.HttpClient;
41
37
 
42
- export const QuestradeProtocol: Layer.Layer<API.Protocol> = /*@__PURE__*/ makeRestProtocol<Config>({
43
- // Resolved on the calling fiber per request, so a refreshed token is
44
- // picked up without rebuilding the layer.
45
- credentials: /*@__PURE__*/ Effect.flatMap(Credentials, (resolve) => resolve),
38
+ export const QuestradeProtocol = /*@__PURE__*/ restProtocol({
39
+ // Resolved on the calling fiber per request, so a refreshed token is picked
40
+ // up.
41
+ credentials: /*@__PURE__*/ Effect.flatten(Credentials),
46
42
  baseUrl: (creds) => creds.apiServer,
47
43
  headers: (creds) => ({ authorization: `Bearer ${Redacted.value(creds.accessToken)}` }),
48
44
  unknownError: (info) => new UnknownQuestradeError(unknownErrorProps(info)),
@@ -2,7 +2,7 @@ import * as API from "@distilled.cloud/core/api";
2
2
  // AUTO-GENERATED by scripts/generate.ts from .generated-specs (specs/spec-mirror-questrade). Do not edit.
3
3
  import * as S from "@distilled.cloud/core/schema-lite";
4
4
  import * as __L from "@distilled.cloud/core/schema-lite";
5
- import { UnknownQuestradeError } from "../errors.ts";
5
+ import { QuestradeServiceErrors } from "../errors.ts";
6
6
  import { QuestradeProtocol, type QuestradeOpError, type QuestradeOpContext } from "../protocol.ts";
7
7
  import * as Retry from "../retry.ts";
8
8
  import * as T from "../traits.ts";
@@ -1296,7 +1296,8 @@ export const cancelOrder: API.OperationMethod<
1296
1296
  > = /*@__PURE__*/ API.make(() => ({
1297
1297
  input: __S(0, __c0, 0) as any as S.Schema<CancelOrderRequest>,
1298
1298
  output: __S(1, __c0, 1) as any as S.Schema<CancelOrderResponse>,
1299
- errors: [UnknownQuestradeError],
1299
+ errors: [],
1300
+ serviceErrors: QuestradeServiceErrors,
1300
1301
  protocol: QuestradeProtocol,
1301
1302
  retry: Retry.Retry,
1302
1303
  telemetry: TELEMETRY,
@@ -1313,7 +1314,8 @@ export const getBalances: API.OperationMethod<
1313
1314
  > = /*@__PURE__*/ API.make(() => ({
1314
1315
  input: __S(8, __c1, 0) as any as S.Schema<GetBalancesRequest>,
1315
1316
  output: __S(11, __c1, 3) as any as S.Schema<GetBalancesResponse>,
1316
- errors: [UnknownQuestradeError],
1317
+ errors: [],
1318
+ serviceErrors: QuestradeServiceErrors,
1317
1319
  protocol: QuestradeProtocol,
1318
1320
  retry: Retry.Retry,
1319
1321
  telemetry: TELEMETRY,
@@ -1330,7 +1332,8 @@ export const getBracketOrderImpact: API.OperationMethod<
1330
1332
  > = /*@__PURE__*/ API.make(() => ({
1331
1333
  input: __S(104, __c13, 0) as any as S.Schema<GetBracketOrderImpactRequest>,
1332
1334
  output: __S(120, __c15, 0) as any as S.Schema<GetBracketOrderImpactResponse>,
1333
- errors: [UnknownQuestradeError],
1335
+ errors: [],
1336
+ serviceErrors: QuestradeServiceErrors,
1334
1337
  protocol: QuestradeProtocol,
1335
1338
  retry: Retry.Retry,
1336
1339
  telemetry: TELEMETRY,
@@ -1347,7 +1350,8 @@ export const getOptionChain: API.OperationMethod<
1347
1350
  > = /*@__PURE__*/ API.make(() => ({
1348
1351
  input: __S(176, __c22, 0) as any as S.Schema<GetOptionChainRequest>,
1349
1352
  output: __S(183, __c22, 7) as any as S.Schema<GetOptionChainResponse>,
1350
- errors: [UnknownQuestradeError],
1353
+ errors: [],
1354
+ serviceErrors: QuestradeServiceErrors,
1351
1355
  protocol: QuestradeProtocol,
1352
1356
  retry: Retry.Retry,
1353
1357
  telemetry: TELEMETRY,
@@ -1364,7 +1368,8 @@ export const getOptionQuotes: API.OperationMethod<
1364
1368
  > = /*@__PURE__*/ API.make(() => ({
1365
1369
  input: __S(187, __c23, 3) as any as S.Schema<GetOptionQuotesRequest>,
1366
1370
  output: __S(190, __c23, 6) as any as S.Schema<GetOptionQuotesResponse>,
1367
- errors: [UnknownQuestradeError],
1371
+ errors: [],
1372
+ serviceErrors: QuestradeServiceErrors,
1368
1373
  protocol: QuestradeProtocol,
1369
1374
  retry: Retry.Retry,
1370
1375
  telemetry: TELEMETRY,
@@ -1381,7 +1386,8 @@ export const getOrder: API.OperationMethod<
1381
1386
  > = /*@__PURE__*/ API.make(() => ({
1382
1387
  input: __S(192, __c24, 0) as any as S.Schema<GetOrderRequest>,
1383
1388
  output: __S(200, __c25, 0) as any as S.Schema<GetOrderResponse>,
1384
- errors: [UnknownQuestradeError],
1389
+ errors: [],
1390
+ serviceErrors: QuestradeServiceErrors,
1385
1391
  protocol: QuestradeProtocol,
1386
1392
  retry: Retry.Retry,
1387
1393
  telemetry: TELEMETRY,
@@ -1398,7 +1404,8 @@ export const getOrderImpact: API.OperationMethod<
1398
1404
  > = /*@__PURE__*/ API.make(() => ({
1399
1405
  input: __S(224, __c28, 0) as any as S.Schema<GetOrderImpactRequest>,
1400
1406
  output: __S(120, __c15, 0) as any as S.Schema<GetOrderImpactResponse>,
1401
- errors: [UnknownQuestradeError],
1407
+ errors: [],
1408
+ serviceErrors: QuestradeServiceErrors,
1402
1409
  protocol: QuestradeProtocol,
1403
1410
  retry: Retry.Retry,
1404
1411
  telemetry: TELEMETRY,
@@ -1415,7 +1422,8 @@ export const getQuote: API.OperationMethod<
1415
1422
  > = /*@__PURE__*/ API.make(() => ({
1416
1423
  input: __S(232, __c29, 0) as any as S.Schema<GetQuoteRequest>,
1417
1424
  output: __S(242, __c30, 2) as any as S.Schema<GetQuoteResponse>,
1418
- errors: [UnknownQuestradeError],
1425
+ errors: [],
1426
+ serviceErrors: QuestradeServiceErrors,
1419
1427
  protocol: QuestradeProtocol,
1420
1428
  retry: Retry.Retry,
1421
1429
  telemetry: TELEMETRY,
@@ -1432,7 +1440,8 @@ export const getStrategyOrderImpact: API.OperationMethod<
1432
1440
  > = /*@__PURE__*/ API.make(() => ({
1433
1441
  input: __S(248, __c31, 0) as any as S.Schema<GetStrategyOrderImpactRequest>,
1434
1442
  output: __S(249, __c31, 1) as any as S.Schema<GetStrategyOrderImpactResponse>,
1435
- errors: [UnknownQuestradeError],
1443
+ errors: [],
1444
+ serviceErrors: QuestradeServiceErrors,
1436
1445
  protocol: QuestradeProtocol,
1437
1446
  retry: Retry.Retry,
1438
1447
  telemetry: TELEMETRY,
@@ -1449,7 +1458,8 @@ export const getStrategyQuotes: API.OperationMethod<
1449
1458
  > = /*@__PURE__*/ API.make(() => ({
1450
1459
  input: __S(268, __c33, 4) as any as S.Schema<GetStrategyQuotesRequest>,
1451
1460
  output: __S(271, __c33, 7) as any as S.Schema<GetStrategyQuotesResponse>,
1452
- errors: [UnknownQuestradeError],
1461
+ errors: [],
1462
+ serviceErrors: QuestradeServiceErrors,
1453
1463
  protocol: QuestradeProtocol,
1454
1464
  retry: Retry.Retry,
1455
1465
  telemetry: TELEMETRY,
@@ -1466,7 +1476,8 @@ export const getSymbol: API.OperationMethod<
1466
1476
  > = /*@__PURE__*/ API.make(() => ({
1467
1477
  input: __S(16, __c2, 0) as any as S.Schema<GetSymbolRequest>,
1468
1478
  output: __S(31, __c3, 7) as any as S.Schema<GetSymbolResponse>,
1469
- errors: [UnknownQuestradeError],
1479
+ errors: [],
1480
+ serviceErrors: QuestradeServiceErrors,
1470
1481
  protocol: QuestradeProtocol,
1471
1482
  retry: Retry.Retry,
1472
1483
  telemetry: TELEMETRY,
@@ -1483,7 +1494,8 @@ export const getTime: API.OperationMethod<
1483
1494
  > = /*@__PURE__*/ API.make(() => ({
1484
1495
  input: __S(32, __c4, 0) as any as S.Schema<GetTimeRequest>,
1485
1496
  output: __S(33, __c4, 1) as any as S.Schema<GetTimeResponse>,
1486
- errors: [UnknownQuestradeError],
1497
+ errors: [],
1498
+ serviceErrors: QuestradeServiceErrors,
1487
1499
  protocol: QuestradeProtocol,
1488
1500
  retry: Retry.Retry,
1489
1501
  telemetry: TELEMETRY,
@@ -1500,7 +1512,8 @@ export const listAccounts: API.OperationMethod<
1500
1512
  > = /*@__PURE__*/ API.make(() => ({
1501
1513
  input: __S(40, __c5, 0) as any as S.Schema<ListAccountsRequest>,
1502
1514
  output: __S(43, __c5, 3) as any as S.Schema<ListAccountsResponse>,
1503
- errors: [UnknownQuestradeError],
1515
+ errors: [],
1516
+ serviceErrors: QuestradeServiceErrors,
1504
1517
  protocol: QuestradeProtocol,
1505
1518
  retry: Retry.Retry,
1506
1519
  telemetry: TELEMETRY,
@@ -1517,7 +1530,8 @@ export const listActivities: API.OperationMethod<
1517
1530
  > = /*@__PURE__*/ API.make(() => ({
1518
1531
  input: __S(48, __c6, 0) as any as S.Schema<ListActivitiesRequest>,
1519
1532
  output: __S(51, __c6, 3) as any as S.Schema<ListActivitiesResponse>,
1520
- errors: [UnknownQuestradeError],
1533
+ errors: [],
1534
+ serviceErrors: QuestradeServiceErrors,
1521
1535
  protocol: QuestradeProtocol,
1522
1536
  retry: Retry.Retry,
1523
1537
  telemetry: TELEMETRY,
@@ -1534,7 +1548,8 @@ export const listCandles: API.OperationMethod<
1534
1548
  > = /*@__PURE__*/ API.make(() => ({
1535
1549
  input: __S(56, __c7, 0) as any as S.Schema<ListCandlesRequest>,
1536
1550
  output: __S(59, __c7, 3) as any as S.Schema<ListCandlesResponse>,
1537
- errors: [UnknownQuestradeError],
1551
+ errors: [],
1552
+ serviceErrors: QuestradeServiceErrors,
1538
1553
  protocol: QuestradeProtocol,
1539
1554
  retry: Retry.Retry,
1540
1555
  telemetry: TELEMETRY,
@@ -1551,7 +1566,8 @@ export const listExecutions: API.OperationMethod<
1551
1566
  > = /*@__PURE__*/ API.make(() => ({
1552
1567
  input: __S(64, __c8, 0) as any as S.Schema<ListExecutionsRequest>,
1553
1568
  output: __S(67, __c8, 3) as any as S.Schema<ListExecutionsResponse>,
1554
- errors: [UnknownQuestradeError],
1569
+ errors: [],
1570
+ serviceErrors: QuestradeServiceErrors,
1555
1571
  protocol: QuestradeProtocol,
1556
1572
  retry: Retry.Retry,
1557
1573
  telemetry: TELEMETRY,
@@ -1568,7 +1584,8 @@ export const listMarkets: API.OperationMethod<
1568
1584
  > = /*@__PURE__*/ API.make(() => ({
1569
1585
  input: __S(72, __c9, 0) as any as S.Schema<ListMarketsRequest>,
1570
1586
  output: __S(76, __c9, 4) as any as S.Schema<ListMarketsResponse>,
1571
- errors: [UnknownQuestradeError],
1587
+ errors: [],
1588
+ serviceErrors: QuestradeServiceErrors,
1572
1589
  protocol: QuestradeProtocol,
1573
1590
  retry: Retry.Retry,
1574
1591
  telemetry: TELEMETRY,
@@ -1585,7 +1602,8 @@ export const listOrders: API.OperationMethod<
1585
1602
  > = /*@__PURE__*/ API.make(() => ({
1586
1603
  input: __S(80, __c10, 0) as any as S.Schema<ListOrdersRequest>,
1587
1604
  output: __S(200, __c25, 0) as any as S.Schema<ListOrdersResponse>,
1588
- errors: [UnknownQuestradeError],
1605
+ errors: [],
1606
+ serviceErrors: QuestradeServiceErrors,
1589
1607
  protocol: QuestradeProtocol,
1590
1608
  retry: Retry.Retry,
1591
1609
  telemetry: TELEMETRY,
@@ -1602,7 +1620,8 @@ export const listPositions: API.OperationMethod<
1602
1620
  > = /*@__PURE__*/ API.make(() => ({
1603
1621
  input: __S(88, __c11, 0) as any as S.Schema<ListPositionsRequest>,
1604
1622
  output: __S(91, __c11, 3) as any as S.Schema<ListPositionsResponse>,
1605
- errors: [UnknownQuestradeError],
1623
+ errors: [],
1624
+ serviceErrors: QuestradeServiceErrors,
1606
1625
  protocol: QuestradeProtocol,
1607
1626
  retry: Retry.Retry,
1608
1627
  telemetry: TELEMETRY,
@@ -1619,7 +1638,8 @@ export const listQuotes: API.OperationMethod<
1619
1638
  > = /*@__PURE__*/ API.make(() => ({
1620
1639
  input: __S(96, __c12, 0) as any as S.Schema<ListQuotesRequest>,
1621
1640
  output: __S(242, __c30, 2) as any as S.Schema<ListQuotesResponse>,
1622
- errors: [UnknownQuestradeError],
1641
+ errors: [],
1642
+ serviceErrors: QuestradeServiceErrors,
1623
1643
  protocol: QuestradeProtocol,
1624
1644
  retry: Retry.Retry,
1625
1645
  telemetry: TELEMETRY,
@@ -1636,7 +1656,8 @@ export const listSymbols: API.OperationMethod<
1636
1656
  > = /*@__PURE__*/ API.make(() => ({
1637
1657
  input: __S(128, __c16, 0) as any as S.Schema<ListSymbolsRequest>,
1638
1658
  output: __S(31, __c3, 7) as any as S.Schema<ListSymbolsResponse>,
1639
- errors: [UnknownQuestradeError],
1659
+ errors: [],
1660
+ serviceErrors: QuestradeServiceErrors,
1640
1661
  protocol: QuestradeProtocol,
1641
1662
  retry: Retry.Retry,
1642
1663
  telemetry: TELEMETRY,
@@ -1653,7 +1674,8 @@ export const placeBracketOrder: API.OperationMethod<
1653
1674
  > = /*@__PURE__*/ API.make(() => ({
1654
1675
  input: __S(136, __c17, 0) as any as S.Schema<PlaceBracketOrderRequest>,
1655
1676
  output: __S(144, __c18, 0) as any as S.Schema<PlaceBracketOrderResponse>,
1656
- errors: [UnknownQuestradeError],
1677
+ errors: [],
1678
+ serviceErrors: QuestradeServiceErrors,
1657
1679
  protocol: QuestradeProtocol,
1658
1680
  retry: Retry.Retry,
1659
1681
  telemetry: TELEMETRY,
@@ -1670,7 +1692,8 @@ export const placeOrder: API.OperationMethod<
1670
1692
  > = /*@__PURE__*/ API.make(() => ({
1671
1693
  input: __S(152, __c19, 0) as any as S.Schema<PlaceOrderRequest>,
1672
1694
  output: __S(144, __c18, 0) as any as S.Schema<PlaceOrderResponse>,
1673
- errors: [UnknownQuestradeError],
1695
+ errors: [],
1696
+ serviceErrors: QuestradeServiceErrors,
1674
1697
  protocol: QuestradeProtocol,
1675
1698
  retry: Retry.Retry,
1676
1699
  telemetry: TELEMETRY,
@@ -1687,7 +1710,8 @@ export const placeStrategyOrder: API.OperationMethod<
1687
1710
  > = /*@__PURE__*/ API.make(() => ({
1688
1711
  input: __S(160, __c20, 0) as any as S.Schema<PlaceStrategyOrderRequest>,
1689
1712
  output: __S(144, __c18, 0) as any as S.Schema<PlaceStrategyOrderResponse>,
1690
- errors: [UnknownQuestradeError],
1713
+ errors: [],
1714
+ serviceErrors: QuestradeServiceErrors,
1691
1715
  protocol: QuestradeProtocol,
1692
1716
  retry: Retry.Retry,
1693
1717
  telemetry: TELEMETRY,
@@ -1704,7 +1728,8 @@ export const searchSymbols: API.OperationMethod<
1704
1728
  > = /*@__PURE__*/ API.make(() => ({
1705
1729
  input: __S(168, __c21, 0) as any as S.Schema<SearchSymbolsRequest>,
1706
1730
  output: __S(171, __c21, 3) as any as S.Schema<SearchSymbolsResponse>,
1707
- errors: [UnknownQuestradeError],
1731
+ errors: [],
1732
+ serviceErrors: QuestradeServiceErrors,
1708
1733
  protocol: QuestradeProtocol,
1709
1734
  retry: Retry.Retry,
1710
1735
  telemetry: TELEMETRY,