@tidelight/sdk 0.0.0-stage → 0.1.1
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/CHANGELOG.md +11 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +50 -2
- package/dist/index.d.ts +175 -0
- package/dist/index.js +263 -0
- package/package.json +34 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
- Publish the coordinated package set at `0.1.1` with no API contract changes.
|
|
6
|
+
|
|
7
|
+
## 0.1.0
|
|
8
|
+
|
|
9
|
+
- Add a typed TypeScript client for supported Tidelight API v1 market, research job, and webhook operations.
|
|
10
|
+
- Add bounded retries, request timeouts, pagination, and request ID handling.
|
|
11
|
+
- Keep credentials caller supplied and server side.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright 2026 TidelightOrg
|
|
2
|
+
|
|
3
|
+
This package contains Tidelight-authored package source and documentation in this package directory. Those package files are licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
4
|
+
|
|
5
|
+
This package-scoped license does not apply to the mother repository as a whole, Tidelight's proprietary application or backend, research engines, provider integrations, server secrets, or commercial infrastructure. Third-party dependencies retain their own licenses. Tidelight names and marks are not licensed by this notice.
|
package/README.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Tidelight TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official TypeScript client for supported Tidelight Intelligence Cloud v1 market, asynchronous company research, and webhook endpoints. Research calls require `research:run`; webhook calls require `alerts:manage`.
|
|
4
|
+
|
|
5
|
+
Install with `npm install @tidelight/sdk`. Keep the API key on your server.
|
|
6
|
+
|
|
7
|
+
Build locally with `npm run build` in this directory.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { TidelightClient } from "@tidelight/sdk";
|
|
11
|
+
|
|
12
|
+
const client = new TidelightClient({ apiKey: process.env.TIDELIGHT_API_KEY! });
|
|
13
|
+
const page = await client.listTokenizedEquities({ limit: 20, underlyingTicker: "AAPL" });
|
|
14
|
+
for (const instrument of page.data) console.log(instrument.symbol, instrument.underlying_ticker);
|
|
15
|
+
|
|
16
|
+
for await (const instrument of client.tokenizedEquities({ limit: 50 })) {
|
|
17
|
+
console.log(instrument.symbol);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const accepted = await client.startCompanyResearch("NVDA", crypto.randomUUID());
|
|
21
|
+
const result = await client.waitForResearchJob(accepted.job_id, { intervalMs: 2000, timeoutMs: 120000 });
|
|
22
|
+
if (result.status === "complete") console.log(result.result);
|
|
23
|
+
|
|
24
|
+
const created = await client.createWebhook({
|
|
25
|
+
name: "Research events",
|
|
26
|
+
url: "https://your-service.example/tidelight",
|
|
27
|
+
events: ["research.job.completed", "research.job.failed"],
|
|
28
|
+
});
|
|
29
|
+
if (!created.signing_secret) throw new Error("The create response did not include its one-time signing secret.");
|
|
30
|
+
// TODO: Persist created.signing_secret with your approved secrets manager before
|
|
31
|
+
// finishing setup. Do not print it. It cannot be recovered by listing the endpoint.
|
|
32
|
+
const deliveries = await client.listWebhookDeliveries();
|
|
33
|
+
console.log(deliveries.deliveries);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Webhook mutations are not retried automatically because the API does not yet accept webhook idempotency keys; this avoids duplicate endpoint creation or secret rotation after an ambiguous timeout. Webhook destination reachability and DNS safety are checked by the API. A client-side HTTPS check is not an authorization to deliver to a destination.
|
|
37
|
+
|
|
38
|
+
The client retries network errors, 429, and transient 5xx statuses at most twice by default. It enforces a 10 second request timeout and returns `TidelightApiError` with status, code, and request ID.
|
|
39
|
+
|
|
40
|
+
## Run the asynchronous research example
|
|
41
|
+
|
|
42
|
+
From a mother-repository checkout:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npm ci --prefix sdk/typescript
|
|
46
|
+
npm test --prefix sdk/typescript
|
|
47
|
+
export TIDELIGHT_API_KEY='tl_test_…'
|
|
48
|
+
node sdk/typescript/examples/research.mjs NVDA
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The example calls the SDK company snapshot job flow and prints a result only after the API reports `complete`. It preserves job and request IDs and never prints the key. CI injects a mock transport and makes no network calls. A live run requires `research:run` and consumes project quota (10 jobs per rolling hour).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
export type TokenizedEquityInstrument = {
|
|
2
|
+
symbol: string;
|
|
3
|
+
instrument_type: "tokenized_equity_spot";
|
|
4
|
+
underlying_ticker: string;
|
|
5
|
+
issuer_name: string;
|
|
6
|
+
quote_currency: string;
|
|
7
|
+
last_price: number;
|
|
8
|
+
change_24h: number | null;
|
|
9
|
+
provider_timestamp: number | null;
|
|
10
|
+
market_session_status: "available" | "unavailable";
|
|
11
|
+
source: "Bitget Reality spot";
|
|
12
|
+
};
|
|
13
|
+
export type InstrumentPage = {
|
|
14
|
+
data: TokenizedEquityInstrument[];
|
|
15
|
+
next_cursor: string | null;
|
|
16
|
+
generated_at: number;
|
|
17
|
+
request_id: string;
|
|
18
|
+
};
|
|
19
|
+
export type ResearchJobStatus = "queued" | "running" | "retry_wait" | "complete" | "failed" | "cancelled";
|
|
20
|
+
export type ResearchJob = {
|
|
21
|
+
job_id: string;
|
|
22
|
+
ticker: string;
|
|
23
|
+
status: ResearchJobStatus;
|
|
24
|
+
attempts: number;
|
|
25
|
+
max_attempts: number;
|
|
26
|
+
result: Record<string, unknown> | null;
|
|
27
|
+
error: {
|
|
28
|
+
code: string;
|
|
29
|
+
message: string;
|
|
30
|
+
} | null;
|
|
31
|
+
created_at: string;
|
|
32
|
+
started_at: string | null;
|
|
33
|
+
completed_at: string | null;
|
|
34
|
+
retry_at: string | null;
|
|
35
|
+
request_id: string;
|
|
36
|
+
};
|
|
37
|
+
export type WebhookEvent = "research.job.completed" | "research.job.failed";
|
|
38
|
+
export type WebhookEndpoint = {
|
|
39
|
+
id: string;
|
|
40
|
+
project_id: string;
|
|
41
|
+
organization_id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
url: string;
|
|
44
|
+
events: WebhookEvent[];
|
|
45
|
+
enabled: boolean;
|
|
46
|
+
created_at: string;
|
|
47
|
+
updated_at: string;
|
|
48
|
+
};
|
|
49
|
+
export type WebhookDelivery = {
|
|
50
|
+
id: string;
|
|
51
|
+
endpoint_id: string;
|
|
52
|
+
project_id: string;
|
|
53
|
+
event_id: string;
|
|
54
|
+
event_type: WebhookEvent;
|
|
55
|
+
payload: Record<string, unknown>;
|
|
56
|
+
status: "pending" | "sending" | "retry_wait" | "succeeded" | "failed" | "cancelled";
|
|
57
|
+
attempt_count: number;
|
|
58
|
+
last_status_code: number | null;
|
|
59
|
+
last_error_code: string | null;
|
|
60
|
+
last_duration_ms: number | null;
|
|
61
|
+
created_at: string;
|
|
62
|
+
completed_at: string | null;
|
|
63
|
+
endpoint_name: string;
|
|
64
|
+
tic_webhook_delivery_attempts: Array<{
|
|
65
|
+
attempt_number: number;
|
|
66
|
+
status_code: number | null;
|
|
67
|
+
duration_ms: number | null;
|
|
68
|
+
error_code: string | null;
|
|
69
|
+
created_at: string;
|
|
70
|
+
}>;
|
|
71
|
+
};
|
|
72
|
+
export type WebhookMutationResponse = {
|
|
73
|
+
endpoint: WebhookEndpoint;
|
|
74
|
+
signing_secret?: string;
|
|
75
|
+
request_id: string;
|
|
76
|
+
};
|
|
77
|
+
export type WebhookEndpointInput = {
|
|
78
|
+
name: string;
|
|
79
|
+
url: string;
|
|
80
|
+
events: WebhookEvent[];
|
|
81
|
+
};
|
|
82
|
+
export type WebhookEndpointUpdate = {
|
|
83
|
+
name?: string;
|
|
84
|
+
url?: string;
|
|
85
|
+
events?: WebhookEvent[];
|
|
86
|
+
enabled?: boolean;
|
|
87
|
+
rotate_secret?: true;
|
|
88
|
+
};
|
|
89
|
+
export declare class TidelightApiError extends Error {
|
|
90
|
+
readonly status: number;
|
|
91
|
+
readonly code: string;
|
|
92
|
+
readonly requestId: string | null;
|
|
93
|
+
constructor(status: number, code: string, message: string, requestId: string | null);
|
|
94
|
+
}
|
|
95
|
+
type Fetch = typeof fetch;
|
|
96
|
+
export type TidelightClientOptions = {
|
|
97
|
+
apiKey: string;
|
|
98
|
+
baseUrl?: string;
|
|
99
|
+
timeoutMs?: number;
|
|
100
|
+
maxRetries?: number;
|
|
101
|
+
fetch?: Fetch;
|
|
102
|
+
};
|
|
103
|
+
export declare class TidelightClient {
|
|
104
|
+
private readonly apiKey;
|
|
105
|
+
private readonly baseUrl;
|
|
106
|
+
private readonly timeoutMs;
|
|
107
|
+
private readonly maxRetries;
|
|
108
|
+
private readonly transport;
|
|
109
|
+
constructor(options: TidelightClientOptions);
|
|
110
|
+
listTokenizedEquities(options?: {
|
|
111
|
+
limit?: number;
|
|
112
|
+
cursor?: string;
|
|
113
|
+
underlyingTicker?: string;
|
|
114
|
+
signal?: AbortSignal;
|
|
115
|
+
}): Promise<InstrumentPage>;
|
|
116
|
+
startCompanyResearch(ticker: string, idempotencyKey: string, options?: {
|
|
117
|
+
signal?: AbortSignal;
|
|
118
|
+
}): Promise<{
|
|
119
|
+
job_id: string;
|
|
120
|
+
status: ResearchJobStatus;
|
|
121
|
+
duplicate: boolean;
|
|
122
|
+
request_id: string;
|
|
123
|
+
}>;
|
|
124
|
+
getResearchJob(jobId: string, options?: {
|
|
125
|
+
signal?: AbortSignal;
|
|
126
|
+
}): Promise<ResearchJob>;
|
|
127
|
+
cancelResearchJob(jobId: string, options?: {
|
|
128
|
+
signal?: AbortSignal;
|
|
129
|
+
}): Promise<{
|
|
130
|
+
job_id: string;
|
|
131
|
+
status: string;
|
|
132
|
+
request_id: string;
|
|
133
|
+
}>;
|
|
134
|
+
waitForResearchJob(jobId: string, options?: {
|
|
135
|
+
intervalMs?: number;
|
|
136
|
+
timeoutMs?: number;
|
|
137
|
+
signal?: AbortSignal;
|
|
138
|
+
}): Promise<ResearchJob>;
|
|
139
|
+
listWebhooks(options?: {
|
|
140
|
+
signal?: AbortSignal;
|
|
141
|
+
}): Promise<{
|
|
142
|
+
endpoints: WebhookEndpoint[];
|
|
143
|
+
request_id: string;
|
|
144
|
+
}>;
|
|
145
|
+
createWebhook(input: WebhookEndpointInput, options?: {
|
|
146
|
+
signal?: AbortSignal;
|
|
147
|
+
}): Promise<WebhookMutationResponse>;
|
|
148
|
+
updateWebhook(endpointId: string, input: WebhookEndpointUpdate, options?: {
|
|
149
|
+
signal?: AbortSignal;
|
|
150
|
+
}): Promise<WebhookMutationResponse>;
|
|
151
|
+
disableWebhook(endpointId: string, options?: {
|
|
152
|
+
signal?: AbortSignal;
|
|
153
|
+
}): Promise<{
|
|
154
|
+
disabled: true;
|
|
155
|
+
request_id: string;
|
|
156
|
+
}>;
|
|
157
|
+
listWebhookDeliveries(options?: {
|
|
158
|
+
signal?: AbortSignal;
|
|
159
|
+
}): Promise<{
|
|
160
|
+
deliveries: WebhookDelivery[];
|
|
161
|
+
request_id: string;
|
|
162
|
+
}>;
|
|
163
|
+
private validateWebhookId;
|
|
164
|
+
private validateWebhookUrl;
|
|
165
|
+
private validateWebhookEvents;
|
|
166
|
+
private validateWebhookInput;
|
|
167
|
+
private validateWebhookUpdate;
|
|
168
|
+
private jobRequest;
|
|
169
|
+
tokenizedEquities(options?: {
|
|
170
|
+
limit?: number;
|
|
171
|
+
signal?: AbortSignal;
|
|
172
|
+
}): AsyncGenerator<TokenizedEquityInstrument>;
|
|
173
|
+
private pause;
|
|
174
|
+
}
|
|
175
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
export class TidelightApiError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
code;
|
|
4
|
+
requestId;
|
|
5
|
+
constructor(status, code, message, requestId) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "TidelightApiError";
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.requestId = requestId;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const DEFAULT_URL = "https://api.tidelight.app/v1";
|
|
14
|
+
export class TidelightClient {
|
|
15
|
+
apiKey;
|
|
16
|
+
baseUrl;
|
|
17
|
+
timeoutMs;
|
|
18
|
+
maxRetries;
|
|
19
|
+
transport;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
if (!/^tl_(test|live)_[A-Za-z0-9_-]{43}$/.test(options.apiKey))
|
|
22
|
+
throw new TypeError("A valid Tidelight API key is required.");
|
|
23
|
+
const base = new URL(options.baseUrl ?? DEFAULT_URL);
|
|
24
|
+
if (base.protocol !== "https:" && !(base.protocol === "http:" && ["localhost", "127.0.0.1"].includes(base.hostname)))
|
|
25
|
+
throw new TypeError("The API URL must use HTTPS.");
|
|
26
|
+
if (base.username || base.password || base.search || base.hash)
|
|
27
|
+
throw new TypeError("The API URL cannot contain credentials, query, or fragment.");
|
|
28
|
+
if (!Number.isInteger(options.timeoutMs ?? 10000) || (options.timeoutMs ?? 10000) < 100 || (options.timeoutMs ?? 10000) > 120000)
|
|
29
|
+
throw new TypeError("timeoutMs must be 100 to 120000.");
|
|
30
|
+
if (!Number.isInteger(options.maxRetries ?? 2) || (options.maxRetries ?? 2) < 0 || (options.maxRetries ?? 2) > 5)
|
|
31
|
+
throw new TypeError("maxRetries must be 0 to 5.");
|
|
32
|
+
this.apiKey = options.apiKey;
|
|
33
|
+
this.baseUrl = base.toString().replace(/\/$/, "");
|
|
34
|
+
this.timeoutMs = options.timeoutMs ?? 10000;
|
|
35
|
+
this.maxRetries = options.maxRetries ?? 2;
|
|
36
|
+
this.transport = options.fetch ?? fetch;
|
|
37
|
+
}
|
|
38
|
+
async listTokenizedEquities(options = {}) {
|
|
39
|
+
const limit = options.limit ?? 20;
|
|
40
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100)
|
|
41
|
+
throw new RangeError("limit must be 1 to 100.");
|
|
42
|
+
if (options.cursor !== undefined && !/^[A-Z0-9]{2,32}$/.test(options.cursor))
|
|
43
|
+
throw new TypeError("Invalid instrument cursor.");
|
|
44
|
+
const underlyingTicker = options.underlyingTicker?.toUpperCase();
|
|
45
|
+
if (underlyingTicker !== undefined && !/^[A-Z][A-Z0-9.]{0,9}$/.test(underlyingTicker))
|
|
46
|
+
throw new TypeError("Invalid underlyingTicker.");
|
|
47
|
+
const url = new URL(`${this.baseUrl}/market/instruments`);
|
|
48
|
+
url.searchParams.set("kind", "rtoken");
|
|
49
|
+
url.searchParams.set("limit", String(limit));
|
|
50
|
+
if (options.cursor)
|
|
51
|
+
url.searchParams.set("cursor", options.cursor);
|
|
52
|
+
if (underlyingTicker)
|
|
53
|
+
url.searchParams.set("underlying_ticker", underlyingTicker);
|
|
54
|
+
for (let attempt = 0;; attempt++) {
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
const onAbort = () => controller.abort();
|
|
57
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
58
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
59
|
+
let response;
|
|
60
|
+
let payload = null;
|
|
61
|
+
try {
|
|
62
|
+
response = await this.transport(url, { headers: { Authorization: `Bearer ${this.apiKey}`, Accept: "application/json" }, signal: controller.signal });
|
|
63
|
+
try {
|
|
64
|
+
payload = await response.json();
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
payload = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (options.signal?.aborted)
|
|
72
|
+
throw error;
|
|
73
|
+
if (attempt >= this.maxRetries)
|
|
74
|
+
throw new TidelightApiError(0, "network_error", "The Tidelight API could not be reached.", null);
|
|
75
|
+
await this.pause(attempt, undefined, options.signal);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
81
|
+
}
|
|
82
|
+
if (response.ok) {
|
|
83
|
+
if (!payload || typeof payload !== "object" || !("data" in payload) || !Array.isArray(payload.data))
|
|
84
|
+
throw new TidelightApiError(response.status, "invalid_response", "The Tidelight API returned an invalid response.", response.headers.get("x-request-id"));
|
|
85
|
+
return payload;
|
|
86
|
+
}
|
|
87
|
+
const detail = payload && typeof payload === "object" && "error" in payload && payload.error && typeof payload.error === "object" ? payload.error : {};
|
|
88
|
+
if ([429, 502, 503, 504].includes(response.status) && attempt < this.maxRetries) {
|
|
89
|
+
await this.pause(attempt, response.headers.get("retry-after"), options.signal);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
throw new TidelightApiError(response.status, typeof detail.code === "string" ? detail.code : "api_error", typeof detail.message === "string" ? detail.message : "Tidelight API request failed.", typeof detail.request_id === "string" ? detail.request_id : response.headers.get("x-request-id"));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async startCompanyResearch(ticker, idempotencyKey, options = {}) {
|
|
96
|
+
if (!/^[A-Za-z][A-Za-z0-9.]{0,9}$/.test(ticker))
|
|
97
|
+
throw new TypeError("ticker must be a supported stock symbol.");
|
|
98
|
+
if (!/^[A-Za-z0-9._:-]{8,128}$/.test(idempotencyKey))
|
|
99
|
+
throw new TypeError("idempotencyKey must be 8 to 128 valid characters.");
|
|
100
|
+
return this.jobRequest("/research/jobs", "POST", { ticker }, idempotencyKey, options.signal);
|
|
101
|
+
}
|
|
102
|
+
async getResearchJob(jobId, options = {}) {
|
|
103
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(jobId))
|
|
104
|
+
throw new TypeError("Invalid research job ID.");
|
|
105
|
+
return this.jobRequest(`/research/jobs/${jobId}`, "GET", undefined, undefined, options.signal);
|
|
106
|
+
}
|
|
107
|
+
async cancelResearchJob(jobId, options = {}) {
|
|
108
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(jobId))
|
|
109
|
+
throw new TypeError("Invalid research job ID.");
|
|
110
|
+
return this.jobRequest(`/research/jobs/${jobId}`, "DELETE", undefined, undefined, options.signal);
|
|
111
|
+
}
|
|
112
|
+
async waitForResearchJob(jobId, options = {}) {
|
|
113
|
+
const intervalMs = options.intervalMs ?? 2000, timeoutMs = options.timeoutMs ?? 120000;
|
|
114
|
+
if (!Number.isInteger(intervalMs) || intervalMs < 250 || intervalMs > 30000 || !Number.isInteger(timeoutMs) || timeoutMs < intervalMs || timeoutMs > 600000)
|
|
115
|
+
throw new RangeError("Polling interval or timeout is out of range.");
|
|
116
|
+
const deadline = Date.now() + timeoutMs;
|
|
117
|
+
while (Date.now() < deadline) {
|
|
118
|
+
const job = await this.getResearchJob(jobId, options);
|
|
119
|
+
if (["complete", "failed", "cancelled"].includes(job.status))
|
|
120
|
+
return job;
|
|
121
|
+
await new Promise((resolve, reject) => {
|
|
122
|
+
const done = () => { options.signal?.removeEventListener("abort", abort); resolve(); };
|
|
123
|
+
const timer = setTimeout(done, Math.min(intervalMs, deadline - Date.now()));
|
|
124
|
+
const abort = () => { clearTimeout(timer); options.signal?.removeEventListener("abort", abort); reject(options.signal?.reason); };
|
|
125
|
+
if (options.signal?.aborted)
|
|
126
|
+
abort();
|
|
127
|
+
else
|
|
128
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
throw new TidelightApiError(0, "poll_timeout", "The research job did not finish before the polling timeout.", null);
|
|
132
|
+
}
|
|
133
|
+
async listWebhooks(options = {}) {
|
|
134
|
+
return this.jobRequest("/webhooks", "GET", undefined, undefined, options.signal);
|
|
135
|
+
}
|
|
136
|
+
async createWebhook(input, options = {}) {
|
|
137
|
+
this.validateWebhookInput(input);
|
|
138
|
+
return this.jobRequest("/webhooks", "POST", input, undefined, options.signal, false);
|
|
139
|
+
}
|
|
140
|
+
async updateWebhook(endpointId, input, options = {}) {
|
|
141
|
+
this.validateWebhookId(endpointId);
|
|
142
|
+
this.validateWebhookUpdate(input);
|
|
143
|
+
return this.jobRequest("/webhooks/" + endpointId, "PATCH", input, undefined, options.signal, false);
|
|
144
|
+
}
|
|
145
|
+
async disableWebhook(endpointId, options = {}) {
|
|
146
|
+
this.validateWebhookId(endpointId);
|
|
147
|
+
return this.jobRequest("/webhooks/" + endpointId, "DELETE", undefined, undefined, options.signal, false);
|
|
148
|
+
}
|
|
149
|
+
async listWebhookDeliveries(options = {}) {
|
|
150
|
+
return this.jobRequest("/webhooks/deliveries", "GET", undefined, undefined, options.signal);
|
|
151
|
+
}
|
|
152
|
+
validateWebhookId(id) {
|
|
153
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id))
|
|
154
|
+
throw new TypeError("Invalid webhook endpoint ID.");
|
|
155
|
+
}
|
|
156
|
+
validateWebhookUrl(value) {
|
|
157
|
+
let url;
|
|
158
|
+
try {
|
|
159
|
+
url = new URL(value);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
throw new TypeError("Webhook URL must be a valid public HTTPS URL.");
|
|
163
|
+
}
|
|
164
|
+
if (url.protocol !== "https:" || (url.port && url.port !== "443") || url.username || url.password || url.search || url.hash || value.length > 2048)
|
|
165
|
+
throw new TypeError("Webhook URL must use public HTTPS on port 443 without credentials, query, or fragment.");
|
|
166
|
+
}
|
|
167
|
+
validateWebhookEvents(events) {
|
|
168
|
+
if (!Array.isArray(events) || events.length < 1 || events.length > 2 || new Set(events).size !== events.length || events.some(event => !["research.job.completed", "research.job.failed"].includes(event)))
|
|
169
|
+
throw new TypeError("Choose one or more supported webhook events.");
|
|
170
|
+
}
|
|
171
|
+
validateWebhookInput(input) {
|
|
172
|
+
if (!input || typeof input.name !== "string" || input.name.trim().length < 2 || input.name.trim().length > 80)
|
|
173
|
+
throw new TypeError("Webhook name must be 2 to 80 characters.");
|
|
174
|
+
this.validateWebhookUrl(input.url);
|
|
175
|
+
this.validateWebhookEvents(input.events);
|
|
176
|
+
}
|
|
177
|
+
validateWebhookUpdate(input) {
|
|
178
|
+
if (!input || typeof input !== "object" || Object.keys(input).length === 0 || Object.keys(input).some(key => !["name", "url", "events", "enabled", "rotate_secret"].includes(key)))
|
|
179
|
+
throw new TypeError("Provide at least one supported webhook change.");
|
|
180
|
+
if (input.name !== undefined && (typeof input.name !== "string" || input.name.trim().length < 2 || input.name.trim().length > 80))
|
|
181
|
+
throw new TypeError("Webhook name must be 2 to 80 characters.");
|
|
182
|
+
if (input.url !== undefined)
|
|
183
|
+
this.validateWebhookUrl(input.url);
|
|
184
|
+
if (input.events !== undefined)
|
|
185
|
+
this.validateWebhookEvents(input.events);
|
|
186
|
+
if (input.enabled !== undefined && typeof input.enabled !== "boolean")
|
|
187
|
+
throw new TypeError("enabled must be a boolean.");
|
|
188
|
+
if (input.rotate_secret !== undefined && input.rotate_secret !== true)
|
|
189
|
+
throw new TypeError("rotate_secret can only be true.");
|
|
190
|
+
}
|
|
191
|
+
async jobRequest(path, method, body, idempotencyKey, signal, retrySafe = true) {
|
|
192
|
+
const url = `${this.baseUrl}${path}`;
|
|
193
|
+
const retryLimit = retrySafe ? this.maxRetries : 0;
|
|
194
|
+
for (let attempt = 0;; attempt++) {
|
|
195
|
+
const controller = new AbortController();
|
|
196
|
+
const abort = () => controller.abort(signal?.reason);
|
|
197
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
198
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
199
|
+
let response;
|
|
200
|
+
let payload;
|
|
201
|
+
try {
|
|
202
|
+
const headers = { Authorization: `Bearer ${this.apiKey}`, Accept: "application/json" };
|
|
203
|
+
if (body)
|
|
204
|
+
headers["Content-Type"] = "application/json";
|
|
205
|
+
if (idempotencyKey)
|
|
206
|
+
headers["Idempotency-Key"] = idempotencyKey;
|
|
207
|
+
response = await this.transport(url, { method, headers, ...(body ? { body: JSON.stringify(body) } : {}), signal: controller.signal });
|
|
208
|
+
try {
|
|
209
|
+
payload = await response.json();
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
payload = null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
if (signal?.aborted)
|
|
217
|
+
throw error;
|
|
218
|
+
if (attempt >= retryLimit)
|
|
219
|
+
throw new TidelightApiError(0, "network_error", "The Tidelight API could not be reached.", null);
|
|
220
|
+
await this.pause(attempt, undefined, signal);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
clearTimeout(timer);
|
|
225
|
+
signal?.removeEventListener("abort", abort);
|
|
226
|
+
}
|
|
227
|
+
if (response.ok && payload && typeof payload === "object")
|
|
228
|
+
return payload;
|
|
229
|
+
const detail = payload && typeof payload === "object" && "error" in payload && payload.error && typeof payload.error === "object" ? payload.error : {};
|
|
230
|
+
if ([429, 502, 503, 504].includes(response.status) && attempt < retryLimit) {
|
|
231
|
+
await this.pause(attempt, response.headers.get("retry-after"), signal);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (response.ok)
|
|
235
|
+
throw new TidelightApiError(response.status, "invalid_response", "The Tidelight API returned an invalid response.", response.headers.get("x-request-id"));
|
|
236
|
+
throw new TidelightApiError(response.status, typeof detail.code === "string" ? detail.code : "api_error", typeof detail.message === "string" ? detail.message : "Tidelight API request failed.", typeof detail.request_id === "string" ? detail.request_id : response.headers.get("x-request-id"));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async *tokenizedEquities(options = {}) {
|
|
240
|
+
let cursor;
|
|
241
|
+
do {
|
|
242
|
+
const page = await this.listTokenizedEquities({ ...options, cursor });
|
|
243
|
+
yield* page.data;
|
|
244
|
+
if (page.next_cursor === cursor)
|
|
245
|
+
throw new TidelightApiError(0, "invalid_response", "The API returned a repeated pagination cursor.", page.request_id);
|
|
246
|
+
cursor = page.next_cursor ?? undefined;
|
|
247
|
+
} while (cursor);
|
|
248
|
+
}
|
|
249
|
+
async pause(attempt, retryAfter, signal) {
|
|
250
|
+
const seconds = retryAfter && /^\d+$/.test(retryAfter) ? Number(retryAfter) : null;
|
|
251
|
+
const delay = seconds === null ? Math.min(2000, 250 * 2 ** attempt) : Math.min(5000, seconds * 1000);
|
|
252
|
+
await new Promise((resolve, reject) => {
|
|
253
|
+
if (signal?.aborted) {
|
|
254
|
+
reject(signal.reason);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const timer = setTimeout(done, delay);
|
|
258
|
+
function done() { signal?.removeEventListener("abort", abort); resolve(); }
|
|
259
|
+
function abort() { clearTimeout(timer); signal?.removeEventListener("abort", abort); reject(signal?.reason); }
|
|
260
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidelight/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Official TypeScript client for Tidelight Intelligence Cloud API v1.",
|
|
6
|
+
"homepage": "https://tidelight.app/developers/packages/sdk",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/TidelightOrg/tidelight/issues"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"CHANGELOG.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"NOTICE"
|
|
22
|
+
],
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/TidelightOrg/tidelight.git",
|
|
27
|
+
"directory": "sdk/typescript"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"tidelight",
|
|
31
|
+
"sdk",
|
|
32
|
+
"market-intelligence",
|
|
33
|
+
"research",
|
|
34
|
+
"webhooks"
|
|
35
|
+
]
|
|
36
|
+
}
|