@distilled.cloud/questrade 0.0.0-stage → 1.0.0-rc.19
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/LICENSE +201 -0
- package/README.md +87 -2
- package/lib/.lazy.json +1 -0
- package/lib/_bundle/lazy.js +4 -0
- package/lib/_bundle/sdk.js +2 -0
- package/lib/_bundle/sdk.js.map +1 -0
- package/lib/credentials.d.ts +49 -0
- package/lib/credentials.d.ts.map +1 -0
- package/lib/credentials.js +1 -0
- package/lib/errors.d.ts +50 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +1 -0
- package/lib/index.d.ts +37 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/index.lazy.js +6 -0
- package/lib/index.lazy.js.map +1 -0
- package/lib/protocol.d.ts +19 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +1 -0
- package/lib/retry.d.ts +50 -0
- package/lib/retry.d.ts.map +1 -0
- package/lib/retry.js +1 -0
- package/lib/services/index.d.ts +2 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +1 -0
- package/lib/services/questrade.d.ts +1228 -0
- package/lib/services/questrade.d.ts.map +1 -0
- package/lib/services/questrade.js +42 -0
- package/lib/services/questrade.js.map +1 -0
- package/lib/services.lazy/index.js +3 -0
- package/lib/services.lazy/questrade.js +3 -0
- package/lib/traits.d.ts +10 -0
- package/lib/traits.d.ts.map +1 -0
- package/lib/traits.js +1 -0
- package/package.json +81 -3
- package/src/credentials.ts +216 -0
- package/src/errors.ts +77 -0
- package/src/index.ts +36 -0
- package/src/protocol.ts +55 -0
- package/src/retry.ts +69 -0
- package/src/services/index.ts +2 -0
- package/src/services/questrade.ts +2666 -0
- package/src/traits.ts +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @distilled.cloud/questrade
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Effect-native [Questrade](https://www.questrade.com) SDK, generated from the
|
|
4
|
+
[Questrade API documentation](https://www.questrade.com/api/documentation/getting-started).
|
|
5
|
+
|
|
6
|
+
Questrade publishes no OpenAPI document. The spec mirror
|
|
7
|
+
(`distilled-mirror/spec-mirror-questrade`) transcribes every documentation
|
|
8
|
+
page into JSON, and `scripts/docs-to-openapi.ts` reads the property tables and
|
|
9
|
+
sample requests and responses into an OpenAPI document. Where the
|
|
10
|
+
documentation contradicts itself, a patch in `patches/` holds the fix and its
|
|
11
|
+
evidence.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @distilled.cloud/questrade effect
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { Effect, Layer } from "effect";
|
|
23
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
24
|
+
import * as Questrade from "@distilled.cloud/questrade";
|
|
25
|
+
|
|
26
|
+
const program = Effect.gen(function* () {
|
|
27
|
+
const { accounts = [] } = yield* Questrade.listAccounts({});
|
|
28
|
+
const account = accounts[0]?.number;
|
|
29
|
+
if (account === undefined) return;
|
|
30
|
+
|
|
31
|
+
const balances = yield* Questrade.getBalances({ id: account });
|
|
32
|
+
const { positions = [] } = yield* Questrade.listPositions({ id: account });
|
|
33
|
+
const { symbols = [] } = yield* Questrade.searchSymbols({ prefix: "SHOP" });
|
|
34
|
+
const symbolId = symbols[0]?.symbolId;
|
|
35
|
+
const quote =
|
|
36
|
+
symbolId === undefined ? undefined : yield* Questrade.getQuote({ id: symbolId });
|
|
37
|
+
|
|
38
|
+
return { balances: balances.combinedBalances, positions, quote: quote?.quotes?.[0] };
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const Live = Layer.mergeAll(
|
|
42
|
+
FetchHttpClient.layer,
|
|
43
|
+
Questrade.CredentialsFromEnv,
|
|
44
|
+
Questrade.QuestradeProtocol,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
program.pipe(Effect.provide(Live), Effect.runPromise).then(console.log);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Auth
|
|
51
|
+
|
|
52
|
+
Questrade uses OAuth 2.0. For a personal app, generate a refresh token in the
|
|
53
|
+
API Centre (**API centre → Personal apps → New manual authorization**) and set:
|
|
54
|
+
|
|
55
|
+
| Variable | Meaning |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `QUESTRADE_REFRESH_TOKEN` | Refresh token from the API Centre. Redeemed on first use. |
|
|
58
|
+
| `QUESTRADE_LOGIN_URL` | Optional. Default `https://login.questrade.com`; `https://practicelogin.questrade.com` for a practice account. |
|
|
59
|
+
| `QUESTRADE_ACCESS_TOKEN` + `QUESTRADE_API_SERVER` | Optional. Use a token you already hold; no refresh. |
|
|
60
|
+
|
|
61
|
+
The SDK redeems the refresh token at `GET /oauth2/token`, sends the access
|
|
62
|
+
token as `Authorization: Bearer`, and calls the `api_server` the redemption
|
|
63
|
+
names. The access token lives 30 minutes; the SDK redeems again shortly before
|
|
64
|
+
it expires.
|
|
65
|
+
|
|
66
|
+
A refresh token works **once**: each redemption returns the next one. To keep
|
|
67
|
+
a program able to start again, store the new token with `fromRefreshToken`:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import * as Redacted from "effect/Redacted";
|
|
71
|
+
|
|
72
|
+
const Credentials = Questrade.fromRefreshToken({
|
|
73
|
+
refreshToken: Redacted.make(savedRefreshToken),
|
|
74
|
+
onRefresh: (tokens) => saveRefreshToken(Redacted.value(tokens.refreshToken)),
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Operations
|
|
79
|
+
|
|
80
|
+
| Area | Operations |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| Account | `getTime`, `listAccounts`, `getBalances`, `listPositions`, `listOrders`, `getOrder`, `listExecutions`, `listActivities` |
|
|
83
|
+
| Market data | `listMarkets`, `getSymbol`, `listSymbols`, `searchSymbols`, `getOptionChain`, `getQuote`, `listQuotes`, `getOptionQuotes`, `getStrategyQuotes`, `listCandles` |
|
|
84
|
+
| Orders (partner apps, `trade` scope) | `placeOrder`, `getOrderImpact`, `cancelOrder`, `placeBracketOrder`, `getBracketOrderImpact`, `placeStrategyOrder`, `getStrategyOrderImpact` |
|
|
85
|
+
|
|
86
|
+
Placing orders needs the `trade` scope, which Questrade grants to partner
|
|
87
|
+
developers only. Streaming (`GET /v1/notifications`, `?stream=true` quotes over
|
|
88
|
+
WebSocket) is not covered.
|
package/lib/.lazy.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"serviceDirs":["services"],"twins":["index.js"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{api$D as e,api$call as t,api$named as n,api$op as r,category$withParseError as i,category$withServerError as a,config$Redacted as o,config$String as s,config$all as ee,config$option as c,config$withDefault as te,retry$capped as ne,retry$jittered as re,retry$makeDefault as l,retry$throttlingFactory as ie,retry$throttlingOptions as ae,retry$transientFactory as oe,retry$transientOptions as se,schema_lite_typed$String as u,schema_lite_typed$TaggedError as d,schema_lite_typed$Unknown as f,schema_lite_typed$optional as p,trait$Body as ce,trait$FormDataFile as le,trait$Header as ue,trait$Http as de,trait$HttpBody as m,trait$KeyDictionary as h,trait$Label as g,trait$Query as _,trait$ResponseCode as v,trait$UnionCases as y,trait$applyErrorMatchers as b,trait$bodySymbol as x,trait$errorMatchersSymbol as S,trait$formDataFileSymbol as C,trait$getErrorMatchers as w,trait$headerSymbol as T,trait$httpBodySymbol as E,trait$httpSymbol as D,trait$keyDictionarySymbol as O,trait$labelSymbol as k,trait$querySymbol as A,trait$responseCodeSymbol as j,trait$unionCasesSymbol as M}from"@distilled.cloud/core/_bundle/base";import{errors$API_ERRORS as N,errors$BadGateway as P,errors$BadRequest as F,errors$ConfigError as I,errors$Conflict as L,errors$DEFAULT_ERRORS as R,errors$Forbidden as z,errors$GatewayTimeout as B,errors$HTTP_STATUS_MAP as V,errors$InternalServerError as H,errors$Locked as fe,errors$NotFound as pe,errors$ServiceUnavailable as me,errors$TooManyRequests as he,errors$Unauthorized as ge,errors$UnprocessableEntity as _e,protocol_rest$RawResponse as ve,protocol_rest$RawResponseRoot as ye,protocol_rest$SensitiveValue as be,protocol_rest$makeRestProtocol as xe,protocol_rest$rawResponseRootSymbol as Se,protocol_rest$rawResponseSymbol as Ce,protocol_rest$sensitiveValueSymbol as we,schema_lite$Array as Te,schema_lite$Boolean as Ee,schema_lite$NullOr as De,schema_lite$Number as Oe,schema_lite$String as ke,schema_lite$Struct as Ae,schema_lite$Unknown as je,schema_lite$at as Me,schema_lite$optional as Ne,schema_lite$suspend as Pe}from"@distilled.cloud/core/_bundle/rest";import*as U from"effect/Context";import*as W from"effect/Effect";import*as G from"effect/Layer";import*as K from"effect/Option";import*as q from"effect/Redacted";import*as J from"effect/Semaphore";const Y=`https://login.questrade.com`;const X=6e4;var Credentials=class extends (/*@__PURE__*/ U.Service()(`QuestradeCredentials`)){};const normalizeApiServer=e=>e.replace(/\/+$/,``).replace(/\/v1$/,``);const tokenError=e=>new I({message:`Questrade refresh token redemption failed: ${e}`});const redeemRefreshToken=(e,t=Y)=>W.gen(function*(){const n=new URL(`/oauth2/token`,t);n.searchParams.set(`grant_type`,`refresh_token`);n.searchParams.set(`refresh_token`,q.value(e));const r=yield*W.tryPromise({try:()=>fetch(n,{headers:{accept:`application/json`}}),catch:e=>tokenError(`request to ${t} failed: ${String(e)}`)});if(!r.ok)return yield*tokenError(`${t} answered ${r.status} ${r.statusText} (a refresh token redeems once -- use the one the last redemption returned)`);const{access_token:i,refresh_token:a,api_server:o,expires_in:s}=(yield*W.tryPromise({try:()=>r.json(),catch:()=>tokenError(`${t} answered with a body that is not JSON`)}))??{};if(typeof i!==`string`||typeof a!==`string`||typeof o!==`string`)return yield*tokenError(`the answer has no access_token, refresh_token or api_server`);return{accessToken:q.make(i),refreshToken:q.make(a),apiServer:normalizeApiServer(o),expiresInSeconds:typeof s===`number`&&s>0?s:1800}});const refreshing=e=>{const t=J.makeUnsafe(1);let n;let r;let i=0;const fresh=()=>r!==void 0&&Date.now()<i?r:void 0;return W.suspend(()=>{const a=fresh();if(a!==void 0)return W.succeed(a);return J.withPermit(t,W.gen(function*(){const t=fresh();if(t!==void 0)return t;const a=yield*e;const o=yield*redeemRefreshToken(n??a.refreshToken,a.loginUrl);n=o.refreshToken;r={accessToken:o.accessToken,apiServer:o.apiServer};i=Date.now()+Math.max(o.expiresInSeconds*1e3-X,X);if(a.onRefresh)yield*a.onRefresh(o);return r}))})};const fromRefreshToken=e=>G.succeed(Credentials,refreshing(W.succeed(e)));const fromAccessToken=e=>G.succeed(Credentials,W.succeed({accessToken:e.accessToken,apiServer:normalizeApiServer(e.apiServer)}));const Z=/*@__PURE__*/ ee({accessToken:/*@__PURE__*/ o(`QUESTRADE_ACCESS_TOKEN`).pipe(c),apiServer:/*@__PURE__*/ s(`QUESTRADE_API_SERVER`).pipe(c),refreshToken:/*@__PURE__*/ o(`QUESTRADE_REFRESH_TOKEN`).pipe(c),loginUrl:/*@__PURE__*/ s(`QUESTRADE_LOGIN_URL`).pipe(/*@__PURE__*/ te(Y))});const Q=`QUESTRADE_REFRESH_TOKEN, or QUESTRADE_ACCESS_TOKEN with QUESTRADE_API_SERVER, is required`;const Fe=/*@__PURE__*/ refreshing(/*@__PURE__*/ Z.pipe(/*@__PURE__*/ W.mapError(()=>new I({message:Q})),/*@__PURE__*/ W.flatMap(({refreshToken:e,loginUrl:t})=>K.isSome(e)?W.succeed({refreshToken:e.value,loginUrl:t}):W.fail(new I({message:Q})))));const Ie=/*@__PURE__*/ G.succeed(Credentials,/*@__PURE__*/ Z.pipe(/*@__PURE__*/ W.mapError(()=>new I({message:Q})),/*@__PURE__*/ W.flatMap(({accessToken:e,apiServer:t})=>K.isSome(e)&&K.isSome(t)?W.succeed({accessToken:e.value,apiServer:normalizeApiServer(t.value)}):Fe)));var UnknownQuestradeError=class extends (/*@__PURE__*/ d()(`UnknownQuestradeError`,{code:/*@__PURE__*/ p(u),message:/*@__PURE__*/ p(u),body:f}).pipe(a)){};var QuestradeParseError=class extends (/*@__PURE__*/ d()(`QuestradeParseError`,{body:f,cause:f}).pipe(i)){};const Le=/*@__PURE__*/ xe({credentials:/*@__PURE__*/ W.flatMap(Credentials,e=>e),baseUrl:e=>e.apiServer,headers:e=>({authorization:`Bearer ${q.value(e.accessToken)}`}),unknownError:({code:e,message:t,body:n})=>new UnknownQuestradeError({code:e!==void 0?String(e):void 0,message:t,body:n}),parseError:({body:e,cause:t})=>new QuestradeParseError({body:e,cause:t})});var Retry=class extends (/*@__PURE__*/ U.Service()(`QuestradeRetry`)){};const policy=e=>W.provide(G.succeed(Retry,e));const $=/*@__PURE__*/ W.provide(/*@__PURE__*/ G.succeed(Retry,{while:()=>false}));const Re=l;const ze=re;const Be=ne;const Ve=ae;const He=/*@__PURE__*/ policy(ie);const Ue=se;const We=/*@__PURE__*/ policy(oe);export{Te as Ub,Ee as Vb,e as a,De as bc,t as c,Oe as cc,Credentials as credentials$Credentials,Ie as credentials$CredentialsFromEnv,Y as credentials$DEFAULT_LOGIN_URL,fromAccessToken as credentials$fromAccessToken,fromRefreshToken as credentials$fromRefreshToken,redeemRefreshToken as credentials$redeemRefreshToken,N as errors$API_ERRORS,P as errors$BadGateway,F as errors$BadRequest,I as errors$ConfigError,L as errors$Conflict,R as errors$DEFAULT_ERRORS,z as errors$Forbidden,B as errors$GatewayTimeout,V as errors$HTTP_STATUS_MAP,H as errors$InternalServerError,fe as errors$Locked,pe as errors$NotFound,QuestradeParseError as errors$QuestradeParseError,me as errors$ServiceUnavailable,he as errors$TooManyRequests,ge as errors$Unauthorized,UnknownQuestradeError as errors$UnknownQuestradeError,_e as errors$UnprocessableEntity,ke as fc,Ae as gc,n as k,je as lc,r as m,Me as nc,Le as protocol$QuestradeProtocol,Retry as retry$Retry,Be as retry$capped,ze as retry$jittered,Re as retry$makeDefault,$ as retry$none,policy as retry$policy,He as retry$throttling,Ve as retry$throttlingOptions,We as retry$transient,Ue as retry$transientOptions,Ne as sc,Pe as tc,ce as traits$Body,le as traits$FormDataFile,ue as traits$Header,de as traits$Http,m as traits$HttpBody,h as traits$KeyDictionary,g as traits$Label,_ as traits$Query,ve as traits$RawResponse,ye as traits$RawResponseRoot,v as traits$ResponseCode,be as traits$SensitiveValue,y as traits$UnionCases,b as traits$applyErrorMatchers,x as traits$bodySymbol,S as traits$errorMatchersSymbol,C as traits$formDataFileSymbol,w as traits$getErrorMatchers,T as traits$headerSymbol,E as traits$httpBodySymbol,D as traits$httpSymbol,O as traits$keyDictionarySymbol,k as traits$labelSymbol,A as traits$querySymbol,Se as traits$rawResponseRootSymbol,Ce as traits$rawResponseSymbol,j as traits$responseCodeSymbol,we as traits$sensitiveValueSymbol,M as traits$unionCasesSymbol};
|
|
2
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","names":["EffectConfig.option","Schema.String","Schema.Unknown","Category.withServerError","Category.withParseError","Retries.makeDefault","Retries.jittered","Retries.capped","Retries.throttlingOptions","Retries.throttlingFactory","Retries.transientOptions","Retries.transientFactory","D","call","named","op","withParseError","withServerError","Redacted$3","String$3","all$1","option","withDefault","capped$1","jittered$1","makeDefault$1","throttlingFactory","throttlingOptions$1","transientFactory","transientOptions$1","String$2","TaggedError$1","Unknown$1","optional$1","Body","FormDataFile","Header","Http","HttpBody","KeyDictionary","Label","Query","ResponseCode","UnionCases","applyErrorMatchers","bodySymbol","errorMatchersSymbol","formDataFileSymbol","getErrorMatchers","headerSymbol","httpBodySymbol","httpSymbol","keyDictionarySymbol","labelSymbol","querySymbol","responseCodeSymbol","unionCasesSymbol","API_ERRORS","BadGateway","BadRequest","ConfigError","Conflict","DEFAULT_ERRORS","Forbidden","GatewayTimeout","HTTP_STATUS_MAP","InternalServerError","Locked","NotFound","ServiceUnavailable","TooManyRequests","Unauthorized","UnprocessableEntity","RawResponse","RawResponseRoot","SensitiveValue","makeRestProtocol","rawResponseRootSymbol","rawResponseSymbol","sensitiveValueSymbol","Array","Boolean","NullOr","Number","String$1","Struct","Unknown","at","optional","suspend","Context","Effect","Layer","Option","Redacted","Semaphore","DEFAULT_LOGIN_URL","REFRESH_WINDOW_MS","url","message","loginUrl","refreshToken","response","cause","access_token","refresh_token","api_server","expires_in","lock","next","cached","refreshAt","hit","raced","config","load","tokens","envConfig","MISSING","fromEnvRefreshToken","CredentialsFromEnv","accessToken","apiServer","QuestradeProtocol","resolve","creds","code","optionsOrFactory","none","makeDefault","jittered","capped","throttlingOptions","throttling","transientOptions","transient"],"sources":["../../src/credentials.ts","../../src/errors.ts","../../src/protocol.ts","../../src/retry.ts"],"mappings":"gvEAkCA,MAAagG,EAAoB,8BAGjC,MAAMC,EAAoB,IAQ1B,IAAa,YAAb,eACwB,gBAAQ,QAAyD,CAAC,CACtF,sBACF,EAAA,AAAE,CAAC,EAoBL,MAAM,mBAAsB,GAAwBC,EAAI,QAAQ,OAAQ,EAAE,CAAC,CAAC,QAAQ,QAAS,EAAE,EAE/F,MAAM,WAAc,GAClB,IAAItC,EAAY,CAAE,QAAS,8CAA8CuC,GAAU,CAAC,EAGtF,MAAa,oBACX,EACA,EAAmBH,IAEnBL,EAAO,IAAI,WAAa,CACtB,MAAMO,EAAM,IAAI,IAAI,gBAAiBE,CAAQ,EAC7CF,EAAI,aAAa,IAAI,aAAc,e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MAAa6H,GAAS5H,GAGtB,MAAa6H,GAA6B5H,GAG1C,MAAa6H,GAE+C,qBAAO5H,EAAyB,EAG5F,MAAa6H,GAA4B5H,GAGzC,MAAa6H,GAE+C,qBAAO5H,EAAwB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Redacted from "effect/Redacted";
|
|
6
|
+
/** The live login server; `https://practicelogin.questrade.com` serves practice accounts. */
|
|
7
|
+
export declare const DEFAULT_LOGIN_URL = "https://login.questrade.com";
|
|
8
|
+
export interface Config {
|
|
9
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
10
|
+
/** The API server the token was issued for, without a trailing `/v1`. */
|
|
11
|
+
readonly apiServer: string;
|
|
12
|
+
}
|
|
13
|
+
declare const Credentials_base: Context.ServiceClass<Credentials, "QuestradeCredentials", Effect.Effect<Config, ConfigError, never>>;
|
|
14
|
+
export declare class Credentials extends /*@__PURE__*/ Credentials_base {
|
|
15
|
+
}
|
|
16
|
+
/** One redemption of a refresh token. */
|
|
17
|
+
export interface Tokens {
|
|
18
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
19
|
+
/** The refresh token to redeem next; the one just spent no longer works. */
|
|
20
|
+
readonly refreshToken: Redacted.Redacted<string>;
|
|
21
|
+
readonly apiServer: string;
|
|
22
|
+
readonly expiresInSeconds: number;
|
|
23
|
+
}
|
|
24
|
+
export interface RefreshTokenConfig {
|
|
25
|
+
readonly refreshToken: Redacted.Redacted<string>;
|
|
26
|
+
/** Default {@link DEFAULT_LOGIN_URL}. */
|
|
27
|
+
readonly loginUrl?: string;
|
|
28
|
+
/** Called with every redemption, to store `tokens.refreshToken`. */
|
|
29
|
+
readonly onRefresh?: (tokens: Tokens) => Effect.Effect<void>;
|
|
30
|
+
}
|
|
31
|
+
/** Redeem a refresh token at the login server. */
|
|
32
|
+
export declare const redeemRefreshToken: (refreshToken: Redacted.Redacted<string>, loginUrl?: string) => Effect.Effect<Tokens, ConfigError>;
|
|
33
|
+
/** Credentials from a refresh token, redeemed on first use and again before each expiry. */
|
|
34
|
+
export declare const fromRefreshToken: (config: RefreshTokenConfig) => Layer.Layer<Credentials>;
|
|
35
|
+
/** Credentials from an access token and the API server it was issued for (no refresh). */
|
|
36
|
+
export declare const fromAccessToken: (config: {
|
|
37
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
38
|
+
readonly apiServer: string;
|
|
39
|
+
}) => Layer.Layer<Credentials>;
|
|
40
|
+
/**
|
|
41
|
+
* `QUESTRADE_ACCESS_TOKEN` + `QUESTRADE_API_SERVER` when both are set;
|
|
42
|
+
* otherwise `QUESTRADE_REFRESH_TOKEN`, redeemed at `QUESTRADE_LOGIN_URL`
|
|
43
|
+
* (default {@link DEFAULT_LOGIN_URL}) on first use. The rotated refresh
|
|
44
|
+
* tokens are kept in memory only -- use {@link fromRefreshToken} with
|
|
45
|
+
* `onRefresh` to store them.
|
|
46
|
+
*/
|
|
47
|
+
export declare const CredentialsFromEnv: Layer.Layer<Credentials>;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C,6FAA6F;AAC7F,eAAO,MAAM,iBAAiB,gCAAgC,CAAC;AAK/D,MAAM,WAAW,MAAM;IACrB,QAAQ,CAA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AAK,CAAC,WAAW,CAOxB,CAAC;AA6BJ;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAavD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { credentials$Credentials as Credentials, credentials$CredentialsFromEnv as CredentialsFromEnv, credentials$DEFAULT_LOGIN_URL as DEFAULT_LOGIN_URL, credentials$fromAccessToken as fromAccessToken, credentials$fromRefreshToken as fromRefreshToken, credentials$redeemRefreshToken as redeemRefreshToken } from "./_bundle/sdk.js";
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Questrade-specific error types.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the shared HTTP status errors from core and adds the Questrade
|
|
5
|
+
* fallback and parse errors.
|
|
6
|
+
*
|
|
7
|
+
* Questrade answers a failure with `{ code, message }` -- `code` is a number
|
|
8
|
+
* such as `1017` ("Access token is invalid", 401) or `1019` ("Symbol not
|
|
9
|
+
* found", 404); see https://www.questrade.com/api/documentation/error-handling.
|
|
10
|
+
* The documentation ties no code to an operation, so the protocol maps the
|
|
11
|
+
* status to core's shared classes and reports any other status as an
|
|
12
|
+
* `UnknownQuestradeError` carrying the code.
|
|
13
|
+
*/
|
|
14
|
+
export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, Locked, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
|
|
15
|
+
import type { BadRequest as CoreBadRequest, Conflict as CoreConflict, DefaultErrors as CoreDefaultErrors, Forbidden as CoreForbidden, Locked as CoreLocked, NotFound as CoreNotFound, UnprocessableEntity as CoreUnprocessableEntity } from "@distilled.cloud/core/errors";
|
|
16
|
+
import * as Schema from "@distilled.cloud/core/schema-lite-typed";
|
|
17
|
+
declare const UnknownQuestradeError_base: Schema.TaggedErrorClass<"UnknownQuestradeError", {
|
|
18
|
+
readonly code: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
19
|
+
readonly message: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
20
|
+
readonly body: import("effect/Schema").Unknown;
|
|
21
|
+
}> & (new (...args: any[]) => {
|
|
22
|
+
"@distilled.cloud/error/categories": {
|
|
23
|
+
ServerError: true;
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Unknown Questrade error -- returned when an error response matches no
|
|
28
|
+
* shared HTTP status class. `code` is the body's numeric `code` as a string.
|
|
29
|
+
*/
|
|
30
|
+
export declare class UnknownQuestradeError extends /*@__PURE__*/ UnknownQuestradeError_base {
|
|
31
|
+
}
|
|
32
|
+
declare const QuestradeParseError_base: Schema.TaggedErrorClass<"QuestradeParseError", {
|
|
33
|
+
readonly body: import("effect/Schema").Unknown;
|
|
34
|
+
readonly cause: import("effect/Schema").Unknown;
|
|
35
|
+
}> & (new (...args: any[]) => {
|
|
36
|
+
"@distilled.cloud/error/categories": {
|
|
37
|
+
ParseError: true;
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
/** A 2xx response that does not match the operation's output schema. */
|
|
41
|
+
export declare class QuestradeParseError extends /*@__PURE__*/ QuestradeParseError_base {
|
|
42
|
+
}
|
|
43
|
+
/** Errors any Questrade operation may surface beyond the core HTTP defaults. */
|
|
44
|
+
export type ClientErrors = UnknownQuestradeError | QuestradeParseError;
|
|
45
|
+
/**
|
|
46
|
+
* Default Questrade operation errors: the shared HTTP status errors from core
|
|
47
|
+
* plus the Questrade client errors.
|
|
48
|
+
*/
|
|
49
|
+
export type DefaultErrors = CoreDefaultErrors | CoreBadRequest | CoreForbidden | CoreNotFound | CoreConflict | CoreUnprocessableEntity | CoreLocked | ClientErrors;
|
|
50
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EACV,UAAU,IAAI,cAAc,EAC5B,QAAQ,IAAI,YAAY,EACxB,aAAa,IAAI,iBAAiB,EAClC,SAAS,IAAI,aAAa,EAC1B,MAAM,IAAI,UAAU,EACpB,QAAQ,IAAI,YAAY,EACxB,mBAAmB,IAAI,uBAAuB,EAC/C,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,yCAAyC,CAAC;;;;;;;;;;AAElE;;;GAGG;AACH,qBAAa,qBACX,SAAQ,aAAa,CAAC,0BAIW;CAAG;;;;;;;;;AAEtC,wEAAwE;AACxE,qBAAa,mBACX,SAAQ,aAAa,CAAC,wBAGU;CAAG;AAErC,gFAAgF;AAChF,MAAM,MAAM,YAAY,GAAG,qBAAqB,GAAG,mBAAmB,CAAC;AAEvE;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB,iBAAiB,GACjB,cAAc,GACd,aAAa,GACb,YAAY,GACZ,YAAY,GACZ,uBAAuB,GACvB,UAAU,GACV,YAAY,CAAC"}
|
package/lib/errors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { errors$API_ERRORS as API_ERRORS, errors$BadGateway as BadGateway, errors$BadRequest as BadRequest, errors$ConfigError as ConfigError, errors$Conflict as Conflict, errors$DEFAULT_ERRORS as DEFAULT_ERRORS, errors$Forbidden as Forbidden, errors$GatewayTimeout as GatewayTimeout, errors$HTTP_STATUS_MAP as HTTP_STATUS_MAP, errors$InternalServerError as InternalServerError, errors$Locked as Locked, errors$NotFound as NotFound, errors$QuestradeParseError as QuestradeParseError, errors$ServiceUnavailable as ServiceUnavailable, errors$TooManyRequests as TooManyRequests, errors$Unauthorized as Unauthorized, errors$UnknownQuestradeError as UnknownQuestradeError, errors$UnprocessableEntity as UnprocessableEntity } from "./_bundle/sdk.js";
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @distilled.cloud/questrade -- Questrade SDK for Effect.
|
|
3
|
+
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy model
|
|
5
|
+
* that `scripts/convert.ts` builds from Questrade's API documentation
|
|
6
|
+
* (transcribed into `specs/spec-mirror-questrade/specs/`; Questrade
|
|
7
|
+
* publishes no OpenAPI document). Everything else in this folder is
|
|
8
|
+
* hand-written.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { Effect, Layer } from "effect";
|
|
13
|
+
* import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
14
|
+
* import * as Questrade from "@distilled.cloud/questrade";
|
|
15
|
+
*
|
|
16
|
+
* const program = Effect.gen(function* () {
|
|
17
|
+
* const { accounts } = yield* Questrade.listAccounts({});
|
|
18
|
+
* const id = accounts?.[0]?.number;
|
|
19
|
+
* if (id === undefined) return;
|
|
20
|
+
* return yield* Questrade.getBalances({ id });
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* program.pipe(
|
|
24
|
+
* Effect.provide(
|
|
25
|
+
* Layer.mergeAll(FetchHttpClient.layer, Questrade.CredentialsFromEnv, Questrade.QuestradeProtocol),
|
|
26
|
+
* ),
|
|
27
|
+
* Effect.runPromise,
|
|
28
|
+
* );
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export * from "./credentials.ts";
|
|
32
|
+
export * from "./errors.ts";
|
|
33
|
+
export * as T from "./traits.ts";
|
|
34
|
+
export { QuestradeProtocol, type QuestradeOpError, type QuestradeOpContext } from "./protocol.ts";
|
|
35
|
+
export * as Retry from "./retry.ts";
|
|
36
|
+
export * from "./services/questrade.ts";
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAClG,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAkD,MAAM,eAAe,CAAC;AAClG,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as API from "@distilled.cloud/core/api";
|
|
2
|
+
import type { ConfigError, InvalidInput } from "@distilled.cloud/core/errors";
|
|
3
|
+
import type { SdkError } from "@distilled.cloud/core/sdk-error";
|
|
4
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
5
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
6
|
+
import type * as Layer from "effect/Layer";
|
|
7
|
+
import { Credentials } from "./credentials.ts";
|
|
8
|
+
import { type DefaultErrors } from "./errors.ts";
|
|
9
|
+
/**
|
|
10
|
+
* Error channel shared by every generated Questrade operation. Generated
|
|
11
|
+
* service files annotate operations with `API.OperationMethod<I, O,
|
|
12
|
+
* QuestradeOpError, QuestradeOpContext>` explicitly so the compiler never
|
|
13
|
+
* infers these back out of the schema generics.
|
|
14
|
+
*/
|
|
15
|
+
export type QuestradeOpError = DefaultErrors | ConfigError | HttpClientError.HttpClientError | InvalidInput | SdkError;
|
|
16
|
+
/** Context (requirements) shared by every generated Questrade operation. */
|
|
17
|
+
export type QuestradeOpContext = Credentials | HttpClient.HttpClient;
|
|
18
|
+
export declare const QuestradeProtocol: Layer.Layer<API.Protocol>;
|
|
19
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAehE,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAA8C,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7F;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,WAAW,GACX,eAAe,CAAC,eAAe,GAC/B,YAAY,GACZ,QAAQ,CAAC;AAEb,4EAA4E;AAC5E,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAErE,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAatD,CAAC"}
|
package/lib/protocol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { protocol$QuestradeProtocol as QuestradeProtocol } from "./_bundle/sdk.js";
|
package/lib/retry.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as Retries from "@distilled.cloud/core/retry";
|
|
2
|
+
/**
|
|
3
|
+
* Questrade retry surface -- a veneer over `@distilled.cloud/core/retry`.
|
|
4
|
+
*
|
|
5
|
+
* The `Retry` service tag is threaded into every generated operation via
|
|
6
|
+
* `API.make({ retry: Retry })`, so a caller-installed policy applies to all
|
|
7
|
+
* Questrade calls below it and core's `makeDefault` is the fallback when none is
|
|
8
|
+
* provided.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import * as Questrade from "@distilled.cloud/questrade";
|
|
13
|
+
*
|
|
14
|
+
* myEffect.pipe(Questrade.Retry.transient);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import * as Context from "effect/Context";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
export type Options = Retries.Options;
|
|
20
|
+
export type Factory = Retries.Factory;
|
|
21
|
+
export type Policy = Retries.Policy;
|
|
22
|
+
declare const Retry_base: Context.ServiceClass<Retry, "QuestradeRetry", Retries.Policy>;
|
|
23
|
+
/** Context tag for configuring retry behavior of Questrade API calls. */
|
|
24
|
+
export declare class Retry extends /*@__PURE__*/ Retry_base {
|
|
25
|
+
}
|
|
26
|
+
/** Provides a custom retry policy to every Questrade API call below it. */
|
|
27
|
+
export declare const policy: {
|
|
28
|
+
(options: Options): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
29
|
+
(factory: Factory): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
30
|
+
};
|
|
31
|
+
/** Disables all automatic retries. */
|
|
32
|
+
export declare const none: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
33
|
+
/**
|
|
34
|
+
* The default retry policy (core's): transient/throttling/retryable errors,
|
|
35
|
+
* capped exponential backoff with jitter, server `retryAfter` hints honored
|
|
36
|
+
* with precedence.
|
|
37
|
+
*/
|
|
38
|
+
export declare const makeDefault: Factory;
|
|
39
|
+
export declare const jittered: <Error, Env>(self: import("effect/Schedule").Schedule<unknown, unknown, Error, Env>) => import("effect/Schedule").Schedule<unknown, unknown, Error, Env>;
|
|
40
|
+
export declare const capped: (max: import("effect/Duration").Duration) => <Error, Env>(self: import("effect/Schedule").Schedule<unknown, unknown, Error, Env>) => import("effect/Schedule").Schedule<unknown, unknown, Error, Env>;
|
|
41
|
+
/** Retry options that retry all throttling errors indefinitely. */
|
|
42
|
+
export declare const throttlingOptions: Options;
|
|
43
|
+
/** Retries all throttling errors indefinitely (honoring server hints). */
|
|
44
|
+
export declare const throttling: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
45
|
+
/** Retry options that retry all transient errors indefinitely. */
|
|
46
|
+
export declare const transientOptions: Options;
|
|
47
|
+
/** Retries all transient errors indefinitely. */
|
|
48
|
+
export declare const transient: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AACvD;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,MAAM,MAAM,OAAO,GAAG,OAAO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AC1E,eAAO,MAAM,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAmD,CAAC;AAE9F,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,OAAkC,CAAC;AAElE,iDAAiD;AACjD,eAAO,MAAM,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAkD,CAAC"}
|
package/lib/retry.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { retry$Retry as Retry, retry$capped as capped, retry$jittered as jittered, retry$makeDefault as makeDefault, retry$none as none, retry$policy as policy, retry$throttling as throttling, retry$throttlingOptions as throttlingOptions, retry$transient as transient, retry$transientOptions as transientOptions } from "./_bundle/sdk.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as questrade from "./questrade.js";
|