@flipstream/sdk 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -0
- package/LICENSE +202 -0
- package/README.md +280 -2
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/auth/discovery.d.ts +21 -0
- package/dist/auth/discovery.js +68 -0
- package/dist/auth/discovery.js.map +1 -0
- package/dist/auth/index.d.ts +5 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/pkce.d.ts +10 -0
- package/dist/auth/pkce.js +25 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/signIn.d.ts +97 -0
- package/dist/auth/signIn.js +133 -0
- package/dist/auth/signIn.js.map +1 -0
- package/dist/auth/transport.d.ts +18 -0
- package/dist/auth/transport.js +26 -0
- package/dist/auth/transport.js.map +1 -0
- package/dist/core/body.d.ts +14 -0
- package/dist/core/body.js +69 -0
- package/dist/core/body.js.map +1 -0
- package/dist/core/call.d.ts +17 -0
- package/dist/core/call.js +116 -0
- package/dist/core/call.js.map +1 -0
- package/dist/core/fetch.d.ts +35 -0
- package/dist/core/fetch.js +105 -0
- package/dist/core/fetch.js.map +1 -0
- package/dist/core/read.d.ts +17 -0
- package/dist/core/read.js +92 -0
- package/dist/core/read.js.map +1 -0
- package/dist/core/result.d.ts +94 -0
- package/dist/core/result.js +40 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/retry.d.ts +40 -0
- package/dist/core/retry.js +41 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/transport.d.ts +62 -0
- package/dist/core/transport.js +9 -0
- package/dist/core/transport.js.map +1 -0
- package/dist/flipstream.d.ts +45 -0
- package/dist/flipstream.js +26 -0
- package/dist/flipstream.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/node/headless.d.ts +20 -0
- package/dist/node/headless.js +28 -0
- package/dist/node/headless.js.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.js +5 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/loopback.d.ts +58 -0
- package/dist/node/loopback.js +126 -0
- package/dist/node/loopback.js.map +1 -0
- package/dist/query/catalog.d.ts +15 -0
- package/dist/query/catalog.js +41 -0
- package/dist/query/catalog.js.map +1 -0
- package/dist/query/errors.d.ts +8 -0
- package/dist/query/errors.js +16 -0
- package/dist/query/errors.js.map +1 -0
- package/dist/query/query.d.ts +27 -0
- package/dist/query/query.js +35 -0
- package/dist/query/query.js.map +1 -0
- package/dist/recorded/query-planner/catalog-google_search_console.json +140 -0
- package/dist/recorded/query-planner/catalog.json +1234 -0
- package/dist/spec/query-planner/index.d.ts +1 -0
- package/dist/spec/query-planner/index.js +3 -0
- package/dist/spec/query-planner/index.js.map +1 -0
- package/dist/spec/query-planner/types.gen.d.ts +300 -0
- package/dist/spec/query-planner/types.gen.js +3 -0
- package/dist/spec/query-planner/types.gen.js.map +1 -0
- package/dist/spec/query-planner/zod.gen.d.ts +325 -0
- package/dist/spec/query-planner/zod.gen.js +137 -0
- package/dist/spec/query-planner/zod.gen.js.map +1 -0
- package/package.json +90 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.4.0](https://github.com/flipstream-io/sdk/compare/typescript-v0.3.0...typescript-v0.4.0) (2026-10-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **typescript:** publish @flipstream/sdk to npm on each release ([#110](https://github.com/flipstream-io/sdk/issues/110)) ([7cb0c53](https://github.com/flipstream-io/sdk/commit/7cb0c53577bfcc3d6306b91803694d59b7f68270)), closes [#25](https://github.com/flipstream-io/sdk/issues/25)
|
|
9
|
+
* **typescript:** sign in from Node with a loopback redirect ([#106](https://github.com/flipstream-io/sdk/issues/106)) ([644dea0](https://github.com/flipstream-io/sdk/commit/644dea05144c820d835090b66aae8c75d23af929))
|
|
10
|
+
* **typescript:** sign in with PKCE and the app's own client ID ([#98](https://github.com/flipstream-io/sdk/issues/98)) ([28961ba](https://github.com/flipstream-io/sdk/commit/28961ba490b1606971901c5ffd49c2f604084537))
|
|
11
|
+
* **typescript:** type the planner's error codes, kept raw when unknown ([#96](https://github.com/flipstream-io/sdk/issues/96)) ([0c6f5b4](https://github.com/flipstream-io/sdk/commit/0c6f5b4ac440e00d12211e6e519f04b3833b4a3f))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* **typescript:** name nothing internal in QueryRequest ([#103](https://github.com/flipstream-io/sdk/issues/103)) ([a15c5a7](https://github.com/flipstream-io/sdk/commit/a15c5a744253c9fb34a9479914201f2d7cd97503))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Code Refactoring
|
|
20
|
+
|
|
21
|
+
* **typescript:** read each service's own error envelope ([#104](https://github.com/flipstream-io/sdk/issues/104)) ([2140afb](https://github.com/flipstream-io/sdk/commit/2140afb4e84930a76dfe48de15161d79729d168d))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Documentation
|
|
25
|
+
|
|
26
|
+
* compile the README's TypeScript examples in CI ([#102](https://github.com/flipstream-io/sdk/issues/102)) ([cdf1788](https://github.com/flipstream-io/sdk/commit/cdf17883b284b8679c08d7a4ce5542fb4100c5ce)), closes [#94](https://github.com/flipstream-io/sdk/issues/94)
|
|
27
|
+
* **typescript:** an npm-ready README for the first public release ([#119](https://github.com/flipstream-io/sdk/issues/119)) ([6e94957](https://github.com/flipstream-io/sdk/commit/6e94957b287f52ea6742b2e54f302ba36d11899e)), closes [#117](https://github.com/flipstream-io/sdk/issues/117)
|
|
28
|
+
* **typescript:** no support contact in the README for 0.x ([#120](https://github.com/flipstream-io/sdk/issues/120)) ([70447dc](https://github.com/flipstream-io/sdk/commit/70447dc54bb5e24cf6c1a734d26804ee0fd8f9f4))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### CI
|
|
32
|
+
|
|
33
|
+
* add [#96](https://github.com/flipstream-io/sdk/issues/96)'s error codes to the public API report ([#101](https://github.com/flipstream-io/sdk/issues/101)) ([51bcc2a](https://github.com/flipstream-io/sdk/commit/51bcc2aa2f9949e5c616aa924b4c5b48bf8cfa4e)), closes [#93](https://github.com/flipstream-io/sdk/issues/93)
|
|
34
|
+
* report the public API surface and lint the packed package ([#97](https://github.com/flipstream-io/sdk/issues/97)) ([3999fba](https://github.com/flipstream-io/sdk/commit/3999fbaddbc30e7ea9e888cca008a809719c35b7)), closes [#93](https://github.com/flipstream-io/sdk/issues/93)
|
|
35
|
+
|
|
36
|
+
## [0.3.0](https://github.com/flipstream-io/sdk/compare/typescript-v0.2.0...typescript-v0.3.0) (2026-10-16)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### ⚠ BREAKING CHANGES
|
|
40
|
+
|
|
41
|
+
* **typescript:** switch the public surface to createFlipstream ([#90](https://github.com/flipstream-io/sdk/issues/90))
|
|
42
|
+
|
|
43
|
+
### Features
|
|
44
|
+
|
|
45
|
+
* **typescript:** switch the public surface to createFlipstream ([#90](https://github.com/flipstream-io/sdk/issues/90)) ([ce98052](https://github.com/flipstream-io/sdk/commit/ce98052b05e6edca7d65f91189dd162b84baa6db))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Miscellaneous
|
|
49
|
+
|
|
50
|
+
* **typescript:** generate types and zod schemas from the specs ([#78](https://github.com/flipstream-io/sdk/issues/78)) ([2039c85](https://github.com/flipstream-io/sdk/commit/2039c85e754e09de1eb6604b9496717c511e0ed2)), closes [#54](https://github.com/flipstream-io/sdk/issues/54)
|
|
51
|
+
* **typescript:** make the package ready for npm, without publishing it ([#82](https://github.com/flipstream-io/sdk/issues/82)) ([a24dbde](https://github.com/flipstream-io/sdk/commit/a24dbdea24f37e77376805d31b90e69a56c8de98)), closes [#74](https://github.com/flipstream-io/sdk/issues/74)
|
|
52
|
+
* **typescript:** retire Fern and the patch script ([#91](https://github.com/flipstream-io/sdk/issues/91)) ([532a35c](https://github.com/flipstream-io/sdk/commit/532a35c9678c128d9eda8265a56ad2fbb9733e2d)), closes [#59](https://github.com/flipstream-io/sdk/issues/59)
|
|
53
|
+
* **typescript:** turn on the strict compiler flags and a type-aware lint ([#92](https://github.com/flipstream-io/sdk/issues/92)) ([4dac8c3](https://github.com/flipstream-io/sdk/commit/4dac8c306278f528d83c056e3b067c9176f15e0c)), closes [#60](https://github.com/flipstream-io/sdk/issues/60)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Tests
|
|
57
|
+
|
|
58
|
+
* **typescript:** pin a truncated 503 on a read at three requests ([#89](https://github.com/flipstream-io/sdk/issues/89)) ([42e9a4b](https://github.com/flipstream-io/sdk/commit/42e9a4b0a7f84d27f351387b99617088dbc468d9))
|
|
59
|
+
* **typescript:** pin two loopback refusals and the redirect's token ([#87](https://github.com/flipstream-io/sdk/issues/87)) ([54477f5](https://github.com/flipstream-io/sdk/commit/54477f5b602debe0719ded2ed05e51b0238e0ef5))
|
|
60
|
+
|
|
61
|
+
## [0.2.0](https://github.com/flipstream-io/sdk/compare/typescript-v0.1.1...typescript-v0.2.0) (2026-10-15)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### ⚠ BREAKING CHANGES
|
|
65
|
+
|
|
66
|
+
* Python returns Pydantic models instead of dicts, and an empty 2xx raises ApiError instead of returning None. TypeScript's `Flipstream.SortSpec.Dir` is now `Flipstream.SortSpecDir`.
|
|
67
|
+
|
|
68
|
+
### Features
|
|
69
|
+
|
|
70
|
+
* type the catalogue, query answers and errors, and check every answer ([#28](https://github.com/flipstream-io/sdk/issues/28)) ([9fcbb58](https://github.com/flipstream-io/sdk/commit/9fcbb58651b149293f60e587c6156dae1ea5ed27))
|
|
71
|
+
* **typescript:** run in a browser, with a token asked per attempt and a distinct abort error ([#26](https://github.com/flipstream-io/sdk/issues/26)) ([b2284aa](https://github.com/flipstream-io/sdk/commit/b2284aa5909ce29a5731d49d591b16bde8009696))
|
|
72
|
+
|
|
73
|
+
## [0.1.1](https://github.com/flipstream-io/sdk/compare/typescript-v0.1.0...typescript-v0.1.1) (2026-10-06)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
### Bug Fixes
|
|
77
|
+
|
|
78
|
+
* **typescript:** stop leaving an abort listener per request ([b727d1e](https://github.com/flipstream-io/sdk/commit/b727d1ee84c7c13ca3d5c51d7d62537ead47167d)), closes [#7](https://github.com/flipstream-io/sdk/issues/7)
|
|
79
|
+
|
|
80
|
+
## 0.1.0 (2026-10-05)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Features
|
|
84
|
+
|
|
85
|
+
* add the query-planner sdk for typescript and python ([08344e2](https://github.com/flipstream-io/sdk/commit/08344e2731f29579fb6ec15383142fa317965b07))
|
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/README.md
CHANGED
|
@@ -1,3 +1,281 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @flipstream/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The TypeScript SDK for Flipstream's APIs: sign in, read the catalogue and run queries, with typed
|
|
4
|
+
requests and checked answers, in Node and in browsers.
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/@flipstream/sdk)
|
|
7
|
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
|
8
|
+
[](https://www.npmjs.com/package/@flipstream/sdk)
|
|
9
|
+
|
|
10
|
+
> **Status: 0.x, and early.** Any 0.x release may change the API. It's built for Flipstream's own
|
|
11
|
+
> tools for now:
|
|
12
|
+
>
|
|
13
|
+
> - **"Sign in with Flipstream" isn't open to other apps yet.** Only Flipstream's own apps have an
|
|
14
|
+
> OAuth client ID.
|
|
15
|
+
> - **ID tokens aren't checked yet,** so don't use a sign-in to tell who a person is. A later
|
|
16
|
+
> release adds the checks.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install @flipstream/sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { createFlipstream, orThrow } from '@flipstream/sdk'
|
|
28
|
+
|
|
29
|
+
// Asked before every attempt: return the current access token.
|
|
30
|
+
const fs = createFlipstream({ token: async () => '<your token>' })
|
|
31
|
+
|
|
32
|
+
const catalog = await fs.catalog.list()
|
|
33
|
+
if (!catalog.ok) console.error(catalog.error.kind) // 'unauthorized', 'unavailable', …
|
|
34
|
+
|
|
35
|
+
const answer = orThrow(
|
|
36
|
+
await fs.query({
|
|
37
|
+
source: '<source>',
|
|
38
|
+
connection_id: '<connection id>',
|
|
39
|
+
dimensions: ['<dimension>'],
|
|
40
|
+
metrics: ['<metric>'],
|
|
41
|
+
}),
|
|
42
|
+
)
|
|
43
|
+
console.log(answer.rows, answer.lastRow)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The catalogue names each source with its dimensions and metrics. `fs.catalog.get({ source })` gives
|
|
47
|
+
one source.
|
|
48
|
+
|
|
49
|
+
## Signing in from Node and the CLI
|
|
50
|
+
|
|
51
|
+
For an app that runs on the person's own machine, or in their terminal: a CLI, a script, a local
|
|
52
|
+
tool. `@flipstream/sdk/node` signs them in through their browser, with OAuth 2.0's authorisation
|
|
53
|
+
code and PKCE. The SDK stores nothing: the tokens are the app's to keep. A web app signs in on its
|
|
54
|
+
server instead (see "In a browser").
|
|
55
|
+
|
|
56
|
+
### With a browser on the same machine
|
|
57
|
+
|
|
58
|
+
`signInWithLoopback` opens a one-time server on `127.0.0.1`, on a port the system chooses, and
|
|
59
|
+
waits for the browser to come back to it.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { createFlipstream, discover } from '@flipstream/sdk'
|
|
63
|
+
import { signInWithLoopback } from '@flipstream/sdk/node'
|
|
64
|
+
|
|
65
|
+
const server = await discover('https://auth.flipstream.io')
|
|
66
|
+
if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
|
|
67
|
+
|
|
68
|
+
const signedIn = await signInWithLoopback({
|
|
69
|
+
server: server.data,
|
|
70
|
+
clientId: '<your client id>',
|
|
71
|
+
scopes: ['<scope>'],
|
|
72
|
+
// Show the person where to sign in: open their browser, or print the URL.
|
|
73
|
+
open: (url) => {
|
|
74
|
+
console.log(`Sign in at ${url}`)
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
|
|
78
|
+
|
|
79
|
+
const fs = createFlipstream({ token: () => signedIn.data.accessToken })
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- **The SDK opens nothing and writes nothing to the terminal.** `open` does that, once the port is
|
|
83
|
+
open.
|
|
84
|
+
- **The port listens on `127.0.0.1` only,** and is closed on every path: signed in, refused, timed
|
|
85
|
+
out (after 5 minutes, or `timeoutMs`), aborted (`signal`), or `open` failing.
|
|
86
|
+
- **The redirect is checked before its code is exchanged:** the sign-in's own state first, then the
|
|
87
|
+
issuer.
|
|
88
|
+
- **`page: { signedIn, failed }`** sets the HTML the browser shows afterwards.
|
|
89
|
+
- **What comes back:** `accessToken`, `scope`, `expiresAt` (ms since the epoch) when the server
|
|
90
|
+
says, and `refreshToken` when it issues one. Never log them.
|
|
91
|
+
|
|
92
|
+
### Over SSH, in CI, or with no display
|
|
93
|
+
|
|
94
|
+
When no browser can come back to this machine, the person opens the URL on another device. The
|
|
95
|
+
redirect then fails to load, and they paste back the address it ended on. `isHeadless` tells you
|
|
96
|
+
when you're in that case.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { discover, finishSignIn, startSignIn } from '@flipstream/sdk'
|
|
100
|
+
import { isHeadless, parsePastedRedirect } from '@flipstream/sdk/node'
|
|
101
|
+
import { createInterface } from 'node:readline/promises'
|
|
102
|
+
|
|
103
|
+
const server = await discover('https://auth.flipstream.io')
|
|
104
|
+
if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
|
|
105
|
+
|
|
106
|
+
if (isHeadless(process.env)) {
|
|
107
|
+
const { url, pending } = await startSignIn({
|
|
108
|
+
server: server.data,
|
|
109
|
+
clientId: '<your client id>',
|
|
110
|
+
redirectUri: 'http://127.0.0.1:8976/callback',
|
|
111
|
+
scopes: ['<scope>'],
|
|
112
|
+
})
|
|
113
|
+
console.log(`Open this on any device and sign in:\n${url}`)
|
|
114
|
+
|
|
115
|
+
const prompt = createInterface({ input: process.stdin, output: process.stdout })
|
|
116
|
+
const pasted = parsePastedRedirect(await prompt.question('Paste the address your browser ended on: '), pending)
|
|
117
|
+
prompt.close()
|
|
118
|
+
if (!pasted.ok) throw new Error(`that isn't this sign-in's redirect: ${pasted.error.kind}`)
|
|
119
|
+
|
|
120
|
+
const signedIn = await finishSignIn(pasted.callbackUrl, pending)
|
|
121
|
+
if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- **`isHeadless(env)`** is true in CI, in an SSH session, and on Linux without a display.
|
|
126
|
+
- **`parsePastedRedirect`** checks the pasted address as the loopback checks a redirect, before
|
|
127
|
+
anything is sent. Prompting for it is the app's.
|
|
128
|
+
- **`pending` holds the PKCE verifier,** a secret. Keep it only until the sign-in finishes, and
|
|
129
|
+
never log it.
|
|
130
|
+
|
|
131
|
+
## In a browser
|
|
132
|
+
|
|
133
|
+
The main entry, `@flipstream/sdk`, runs in browsers with no Node polyfills. Only
|
|
134
|
+
`@flipstream/sdk/node` needs Node.
|
|
135
|
+
|
|
136
|
+
- **Pass a token function** that returns the session's current access token. Never put an API key
|
|
137
|
+
in a browser.
|
|
138
|
+
- **The API must allow your page's origin (CORS).** The query API doesn't allow other origins yet,
|
|
139
|
+
so until it does, call it from a server.
|
|
140
|
+
- **Signing in from a page** uses the same two halves as the paste-back above:
|
|
141
|
+
- `startSignIn` gives the URL to send the person to, and a `pending` to keep, for instance in
|
|
142
|
+
`sessionStorage`;
|
|
143
|
+
- when they come back, `finishSignIn(location.href, pending)` checks the redirect and exchanges
|
|
144
|
+
its code.
|
|
145
|
+
- **Browser code shouldn't keep a refresh token.** We recommend signing in on your web app's
|
|
146
|
+
server instead. `startSignIn` and `finishSignIn` work there too, with your app's registered
|
|
147
|
+
https callback as the `redirectUri`, and the server keeps `pending` and the tokens.
|
|
148
|
+
`signInWithLoopback` isn't for this: it waits on the server's own `127.0.0.1`, which the
|
|
149
|
+
person's browser can't reach.
|
|
150
|
+
|
|
151
|
+
## Results, not exceptions
|
|
152
|
+
|
|
153
|
+
Every call settles into a result: `{ ok: true, data }` or `{ ok: false, error }`. A call rejects
|
|
154
|
+
only on a programming error. For instance, a request that can't be sent as JSON (a `BigInt`, a
|
|
155
|
+
cycle) rejects with the `TypeError`, and nothing is sent. `orThrow(result)` gives the data, or
|
|
156
|
+
throws the failure as an `ApiFailure` carrying its `error`, for callers who'd rather catch.
|
|
157
|
+
|
|
158
|
+
- **`fs.catalog.list()`** gives a `Catalog`.
|
|
159
|
+
- **`fs.catalog.get({ source })`** gives a `CatalogSource`: a source plus `catalogVersion`.
|
|
160
|
+
- **`fs.query(request)`** gives a `QueryResponse`, with `rows` and `lastRow`, and sometimes
|
|
161
|
+
`totals` and `timings`. Only the request's declared fields are sent: `source`, `connection_id`,
|
|
162
|
+
`dimensions`, `metrics`, `filters`, `sort`, `offset` and `rows`.
|
|
163
|
+
|
|
164
|
+
**Every answer is checked against the API's spec.** An answer that doesn't match, with a missing
|
|
165
|
+
field or a value of the wrong type, is an `invalid` failure that names the field. It never comes
|
|
166
|
+
back as data. A field the SDK doesn't know yet is kept.
|
|
167
|
+
|
|
168
|
+
## Typed errors
|
|
169
|
+
|
|
170
|
+
`error.kind` says what happened, and each kind has one meaning:
|
|
171
|
+
|
|
172
|
+
| Kind | When |
|
|
173
|
+
|---|---|
|
|
174
|
+
| `unauthorized`, `forbidden`, `not_found`, `conflict`, `rejected` | The API refused: 401, 403, 404, 409 or 412, or any other 4xx |
|
|
175
|
+
| `unavailable` | A 429 or 5xx, or no answer at all (offline, or a connection that broke) |
|
|
176
|
+
| `invalid` | Outside the contract: an answer that isn't JSON or doesn't match its type, or a status no API sends |
|
|
177
|
+
| `timeout` | The call's own deadline passed |
|
|
178
|
+
| `aborted` | The caller's `signal` fired |
|
|
179
|
+
| `refused` | Nothing was sent, by rule: a destination that isn't one of the configured hosts over https, or a `source` of `''`, `.` or `..` |
|
|
180
|
+
| `no_token` | The token function failed, or gave no token. `cause` is what it threw |
|
|
181
|
+
| `cancelled` | The app's own transport cancelled the call, because the session it was made for moved on |
|
|
182
|
+
|
|
183
|
+
**A failure the API answered keeps its `status`.**
|
|
184
|
+
- It keeps the API's `code` and `message` when the body is an error body, or its `text` when it
|
|
185
|
+
isn't (a proxy's `Bad gateway`).
|
|
186
|
+
- `isPlannerCode(error.code)` narrows the code to the ones the query API documents
|
|
187
|
+
(`PlannerErrorCode`), so a switch over them can be exhaustive. A code added since is kept as it
|
|
188
|
+
came.
|
|
189
|
+
- When the API asked the caller to wait, the failure keeps that as `retryAfterMs`.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { isPlannerCode, type ApiError } from '@flipstream/sdk'
|
|
193
|
+
|
|
194
|
+
function explain(error: ApiError): string {
|
|
195
|
+
switch (error.kind) {
|
|
196
|
+
case 'unauthorized':
|
|
197
|
+
return error.code === 'TOKEN_EXPIRED' ? 'Sign in again.' : 'Not signed in.'
|
|
198
|
+
case 'forbidden':
|
|
199
|
+
case 'not_found':
|
|
200
|
+
case 'conflict':
|
|
201
|
+
case 'rejected':
|
|
202
|
+
return isPlannerCode(error.code) ? `${error.code}: ${error.message ?? ''}` : `Refused: ${String(error.status)}`
|
|
203
|
+
case 'unavailable':
|
|
204
|
+
return error.status === undefined ? 'No answer: offline?' : `Busy: try again in ${String(error.retryAfterMs ?? 1000)} ms`
|
|
205
|
+
case 'invalid':
|
|
206
|
+
return `An answer outside the contract: ${error.issues}`
|
|
207
|
+
case 'timeout':
|
|
208
|
+
return 'Too slow.'
|
|
209
|
+
case 'aborted':
|
|
210
|
+
case 'cancelled':
|
|
211
|
+
return 'Stopped.'
|
|
212
|
+
case 'refused':
|
|
213
|
+
return 'Not sent.'
|
|
214
|
+
case 'no_token':
|
|
215
|
+
return 'No token to send.'
|
|
216
|
+
default: {
|
|
217
|
+
const unhandled: never = error
|
|
218
|
+
return unhandled
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Sign-in has a few kinds of its own,** beside the ones above:
|
|
225
|
+
- `wrong_state` and `wrong_issuer`: the redirect isn't this sign-in's;
|
|
226
|
+
- `provider_error`, with the server's `code`: the server ended the sign-in. It's `access_denied`
|
|
227
|
+
when the person declined;
|
|
228
|
+
- `no_code`: the redirect carried no code;
|
|
229
|
+
- `listen_failed` and `open_failed`: from `signInWithLoopback`;
|
|
230
|
+
- `not_a_url`: from `parsePastedRedirect`.
|
|
231
|
+
|
|
232
|
+
There, `refused` also covers an issuer that isn't https, and a `pending` that isn't one (from
|
|
233
|
+
storage the app couldn't read back). Nothing is sent for either.
|
|
234
|
+
|
|
235
|
+
## Options
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
import { createFlipstream } from '@flipstream/sdk'
|
|
239
|
+
|
|
240
|
+
declare const session: { accessToken(rejected?: string): Promise<string> }
|
|
241
|
+
|
|
242
|
+
const fs = createFlipstream({
|
|
243
|
+
// Asked before every attempt; after a 401, asked once more with the token the API refused.
|
|
244
|
+
token: ({ rejected }) => session.accessToken(rejected),
|
|
245
|
+
fetch: globalThis.fetch, // optional: every request goes through it
|
|
246
|
+
hosts: { query: 'https://query.flipstream.io' }, // optional: the default
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
const controller = new AbortController()
|
|
250
|
+
await fs.catalog.list({ signal: controller.signal, deadlineMs: 10_000 })
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
- **The token function** is asked before every attempt, so a renewed token is always the one sent.
|
|
254
|
+
After a 401 it's asked once more with `{ rejected }`, the token the API refused, and the call is
|
|
255
|
+
sent once more. A second 401 is the answer.
|
|
256
|
+
- **The token only goes to the configured hosts, over https.** No redirect is followed, and no
|
|
257
|
+
cookies are sent. Plain http to a loopback host needs `allowLocalhostHttp: true`, for development
|
|
258
|
+
only.
|
|
259
|
+
- **Retries:**
|
|
260
|
+
- A read (`catalog`) is tried again after a 408, 429, 502, 503 or 504, or a connection that
|
|
261
|
+
failed, at most twice. It waits as long as `Retry-After` asks, in seconds, or 500 ms, then 1 s.
|
|
262
|
+
- `query` is never tried again: a timeout at the gateway may already have run on the warehouse.
|
|
263
|
+
- `no_token` and `refused` are never tried again.
|
|
264
|
+
- A wait that wouldn't end before the deadline isn't started.
|
|
265
|
+
- **Deadlines:** 60 s for `query` and 30 s for the rest, every attempt and wait included.
|
|
266
|
+
`deadlineMs` sets one call's.
|
|
267
|
+
- **Abort:** `signal` ends a call at once, also while it waits for a token or to try again.
|
|
268
|
+
- **Your own transport:** an app that attaches the token itself passes `{ transport }` instead of
|
|
269
|
+
`token` and `fetch`. Retries and deadlines still apply, above it.
|
|
270
|
+
|
|
271
|
+
## Requirements
|
|
272
|
+
|
|
273
|
+
- **Node 20.19+ or 22.12+,** or a current browser. Sign-in needs WebCrypto, so a page that signs
|
|
274
|
+
in must be served over https, or from localhost.
|
|
275
|
+
- **ESM.** The package is ES modules only. On these Node versions, `require()` loads it from
|
|
276
|
+
CommonJS too, both entries; Node 22.12 prints an experimental warning when it does.
|
|
277
|
+
- **The types ship in the package,** for both entries.
|
|
278
|
+
|
|
279
|
+
## Licence
|
|
280
|
+
|
|
281
|
+
Apache-2.0.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ApiResult } from '../core/result.js';
|
|
2
|
+
import { type AuthCallOptions } from './transport.js';
|
|
3
|
+
/** What sign-in needs from an authorization server's metadata (RFC 8414), and nothing more. */
|
|
4
|
+
export interface AuthServer {
|
|
5
|
+
/** The issuer as its metadata names it: what a redirect's `iss` must equal (RFC 9207). */
|
|
6
|
+
readonly issuer: string;
|
|
7
|
+
/** Where the person is sent to sign in. */
|
|
8
|
+
readonly authorizationEndpoint: string;
|
|
9
|
+
/** Where the code is exchanged for tokens. */
|
|
10
|
+
readonly tokenEndpoint: string;
|
|
11
|
+
/** The server puts `iss` on every redirect (RFC 9207), so a redirect without one is refused. */
|
|
12
|
+
readonly issuerOnRedirect: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The authorization server at `issuer`, from its RFC 8414 metadata. `refused`, with nothing sent,
|
|
16
|
+
* when `issuer` isn't an https URL. Refused as `invalid`: metadata that doesn't name `issuer`
|
|
17
|
+
* exactly (§3.3), an endpoint that is not an https URL, and a server that doesn't list PKCE's
|
|
18
|
+
* S256, since one that lists no methods supports no PKCE (§2), and a code it issues is bound to no
|
|
19
|
+
* verifier.
|
|
20
|
+
*/
|
|
21
|
+
export declare function discover(issuer: string, options?: AuthCallOptions): Promise<ApiResult<AuthServer>>;
|