@alchemy.run/axiom 0.0.0 → 2.0.0-beta.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +54 -4
  3. package/lib/Annotation.d.ts +51 -0
  4. package/lib/Annotation.d.ts.map +1 -0
  5. package/lib/Annotation.js +97 -0
  6. package/lib/Annotation.js.map +1 -0
  7. package/lib/ApiToken.d.ts +64 -0
  8. package/lib/ApiToken.d.ts.map +1 -0
  9. package/lib/ApiToken.js +123 -0
  10. package/lib/ApiToken.js.map +1 -0
  11. package/lib/AuthProvider.d.ts +40 -0
  12. package/lib/AuthProvider.d.ts.map +1 -0
  13. package/lib/AuthProvider.js +99 -0
  14. package/lib/AuthProvider.js.map +1 -0
  15. package/lib/Chart.d.ts +130 -0
  16. package/lib/Chart.d.ts.map +1 -0
  17. package/lib/Chart.js +14 -0
  18. package/lib/Chart.js.map +1 -0
  19. package/lib/Contributions.d.ts +7 -0
  20. package/lib/Contributions.d.ts.map +1 -0
  21. package/lib/Contributions.js +6 -0
  22. package/lib/Contributions.js.map +1 -0
  23. package/lib/Credentials.d.ts +10 -0
  24. package/lib/Credentials.d.ts.map +1 -0
  25. package/lib/Credentials.js +30 -0
  26. package/lib/Credentials.js.map +1 -0
  27. package/lib/Dashboard.d.ts +112 -0
  28. package/lib/Dashboard.d.ts.map +1 -0
  29. package/lib/Dashboard.js +157 -0
  30. package/lib/Dashboard.js.map +1 -0
  31. package/lib/Dataset.d.ts +120 -0
  32. package/lib/Dataset.d.ts.map +1 -0
  33. package/lib/Dataset.js +215 -0
  34. package/lib/Dataset.js.map +1 -0
  35. package/lib/Monitor.d.ts +76 -0
  36. package/lib/Monitor.d.ts.map +1 -0
  37. package/lib/Monitor.js +126 -0
  38. package/lib/Monitor.js.map +1 -0
  39. package/lib/Notifier.d.ts +65 -0
  40. package/lib/Notifier.d.ts.map +1 -0
  41. package/lib/Notifier.js +112 -0
  42. package/lib/Notifier.js.map +1 -0
  43. package/lib/OtelHeaders.d.ts +9 -0
  44. package/lib/OtelHeaders.d.ts.map +1 -0
  45. package/lib/OtelHeaders.js +9 -0
  46. package/lib/OtelHeaders.js.map +1 -0
  47. package/lib/Providers.d.ts +15 -0
  48. package/lib/Providers.d.ts.map +1 -0
  49. package/lib/Providers.js +34 -0
  50. package/lib/Providers.js.map +1 -0
  51. package/lib/Telemetry.d.ts +66 -0
  52. package/lib/Telemetry.d.ts.map +1 -0
  53. package/lib/Telemetry.js +68 -0
  54. package/lib/Telemetry.js.map +1 -0
  55. package/lib/View.d.ts +57 -0
  56. package/lib/View.d.ts.map +1 -0
  57. package/lib/View.js +100 -0
  58. package/lib/View.js.map +1 -0
  59. package/lib/VirtualField.d.ts +44 -0
  60. package/lib/VirtualField.d.ts.map +1 -0
  61. package/lib/VirtualField.js +97 -0
  62. package/lib/VirtualField.js.map +1 -0
  63. package/lib/index.d.ts +14 -0
  64. package/lib/index.d.ts.map +1 -0
  65. package/lib/index.js +14 -0
  66. package/lib/index.js.map +1 -0
  67. package/package.json +53 -3
  68. package/src/Annotation.ts +121 -0
  69. package/src/ApiToken.ts +148 -0
  70. package/src/AuthProvider.ts +135 -0
  71. package/src/Chart.ts +156 -0
  72. package/src/Contributions.ts +9 -0
  73. package/src/Credentials.ts +68 -0
  74. package/src/Dashboard.ts +192 -0
  75. package/src/Dataset.ts +326 -0
  76. package/src/Monitor.ts +148 -0
  77. package/src/Notifier.ts +136 -0
  78. package/src/OtelHeaders.ts +9 -0
  79. package/src/Providers.ts +60 -0
  80. package/src/Telemetry.ts +116 -0
  81. package/src/View.ts +130 -0
  82. package/src/VirtualField.ts +123 -0
  83. package/src/index.ts +13 -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,9 +1,59 @@
1
1
  # @alchemy.run/axiom
2
2
 
3
- 🐣 This package name has been claimed with [fledgling](https://github.com/dmno-dev/fledgling) for [https://alchemy.run](https://alchemy.run), and a real release will land here soon.
3
+ [Axiom](https://axiom.co) for [Alchemy](https://alchemy.run). Declare OpenTelemetry datasets, ingest tokens, monitors, and dashboards next to the code that emits the data.
4
4
 
5
- This is a placeholder — there is nothing to install yet.
5
+ ```sh
6
+ npm install alchemy @alchemy.run/axiom effect
7
+ ```
6
8
 
7
- ---
9
+ Datasets for traces and logs, an ingest-only token, and a monitor:
8
10
 
9
- Want to claim a name of your own? Run `npx fledgling add <name> --new --yes` — it reserves the name on npm and can set up token-less (OIDC trusted) publishing for when you are ready.
11
+ ```typescript
12
+ // alchemy.run.ts
13
+ import * as Alchemy from "alchemy";
14
+ import * as Axiom from "@alchemy.run/axiom";
15
+ import * as Effect from "effect/Effect";
16
+
17
+ export default Alchemy.Stack(
18
+ "Observability",
19
+ {
20
+ providers: Axiom.providers(),
21
+ state: Alchemy.localState(),
22
+ },
23
+ Effect.gen(function* () {
24
+ const traces = yield* Axiom.Dataset("traces", { name: "app-traces", kind: "otel:traces:v1" });
25
+ const logs = yield* Axiom.Dataset("logs", { name: "app-logs", kind: "otel:logs:v1" });
26
+
27
+ // Can write to the two datasets and nothing else.
28
+ const ingest = yield* Axiom.ApiToken("ingest", {
29
+ name: "app-ingest",
30
+ datasetCapabilities: {
31
+ "app-traces": { ingest: ["create"] },
32
+ "app-logs": { ingest: ["create"] },
33
+ },
34
+ });
35
+
36
+ yield* Axiom.Monitor("panics", {
37
+ name: "Service panic",
38
+ type: "MatchEvent",
39
+ aplQuery: `['app-logs'] | where message contains "panic:"`,
40
+ intervalMinutes: 1,
41
+ rangeMinutes: 1,
42
+ });
43
+
44
+ return {
45
+ tracesEndpoint: traces.otelTracesEndpoint,
46
+ logsEndpoint: logs.otelLogsEndpoint,
47
+ token: ingest.token,
48
+ };
49
+ }),
50
+ );
51
+ ```
52
+
53
+ Pass the endpoints and token to a Worker or Lambda as environment variables and its OpenTelemetry exporter ships straight to Axiom.
54
+
55
+ ## Learn more
56
+
57
+ - [Axiom on alchemy.run](https://alchemy.run/axiom)
58
+ - [Setup](https://alchemy.run/axiom/setup)
59
+ - [Telemetry](https://alchemy.run/infrastructure-as-effects/telemetry)
@@ -0,0 +1,51 @@
1
+ import * as Axiom from "@distilled.cloud/axiom";
2
+ import * as Provider from "alchemy/Provider";
3
+ import { Resource } from "alchemy/Resource";
4
+ import type { Providers } from "./Providers.ts";
5
+ export type AnnotationProps = Axiom.CreateAnnotationRequest;
6
+ export type Annotation = Resource<"Axiom.Annotation", AnnotationProps, Axiom.Annotation, never, Providers>;
7
+ /**
8
+ * An Axiom annotation — a vertical marker overlaid on charts to flag a
9
+ * deploy, incident, feature flag flip, or any other point/range event you
10
+ * want correlated with telemetry.
11
+ *
12
+ * Annotations are scoped to one or more `datasets`. Use a single `time` for
13
+ * a point marker or `time` + `endTime` for a range. The `type` (e.g.
14
+ * `"deploy"`, `"incident"`) groups markers visually in the UI.
15
+ *
16
+ * Although typically created at deploy/release time (out-of-band of
17
+ * regular IaC), modelling them as resources makes per-environment
18
+ * annotation history reproducible.
19
+ * @see https://axiom.co/docs/query-data/annotate-charts
20
+ *
21
+ * ### Creating an Annotation
22
+ * **Example:** Point-in-time deploy marker
23
+ * ```typescript
24
+ * yield* Axiom.Annotation("deploy-1.2.3", {
25
+ * type: "deploy",
26
+ * title: "Release 1.2.3",
27
+ * description: "https://github.com/acme/app/releases/tag/v1.2.3",
28
+ * datasets: ["my-app-traces", "my-app-logs"],
29
+ * time: new Date().toISOString(),
30
+ * url: "https://github.com/acme/app/releases/tag/v1.2.3",
31
+ * });
32
+ * ```
33
+ *
34
+ * **Example:** Incident time-range
35
+ * ```typescript
36
+ * yield* Axiom.Annotation("inc-2026-04-27", {
37
+ * type: "incident",
38
+ * title: "Database failover",
39
+ * datasets: ["my-app-traces"],
40
+ * time: "2026-04-27T18:05:00Z",
41
+ * endTime: "2026-04-27T18:32:00Z",
42
+ * url: "https://incident.io/incidents/abc123",
43
+ * });
44
+ * ```
45
+ *
46
+ * @resource
47
+ * @product Dataset
48
+ */
49
+ export declare const Annotation: import("alchemy/Resource").ResourceClass<Annotation>;
50
+ export declare const AnnotationProvider: () => import("effect/Layer").Layer<Provider.Provider<Annotation>, never, Axiom.AxiomOpContext>;
51
+ //# sourceMappingURL=Annotation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Annotation.d.ts","sourceRoot":"","sources":["../src/Annotation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,uBAAuB,CAAC;AAE5D,MAAM,MAAM,UAAU,GAAG,QAAQ,CAC/B,kBAAkB,EAClB,eAAe,EACf,KAAK,CAAC,UAAU,EAChB,KAAK,EACL,SAAS,CACV,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,UAAU,sDAA2C,CAAC;AAEnE,eAAO,MAAM,kBAAkB,gGA4D5B,CAAC"}
@@ -0,0 +1,97 @@
1
+ import * as Axiom from "@distilled.cloud/axiom";
2
+ import * as Provider from "alchemy/Provider";
3
+ import { Resource } from "alchemy/Resource";
4
+ import * as Effect from "effect/Effect";
5
+ /**
6
+ * An Axiom annotation — a vertical marker overlaid on charts to flag a
7
+ * deploy, incident, feature flag flip, or any other point/range event you
8
+ * want correlated with telemetry.
9
+ *
10
+ * Annotations are scoped to one or more `datasets`. Use a single `time` for
11
+ * a point marker or `time` + `endTime` for a range. The `type` (e.g.
12
+ * `"deploy"`, `"incident"`) groups markers visually in the UI.
13
+ *
14
+ * Although typically created at deploy/release time (out-of-band of
15
+ * regular IaC), modelling them as resources makes per-environment
16
+ * annotation history reproducible.
17
+ * @see https://axiom.co/docs/query-data/annotate-charts
18
+ *
19
+ * ### Creating an Annotation
20
+ * **Example:** Point-in-time deploy marker
21
+ * ```typescript
22
+ * yield* Axiom.Annotation("deploy-1.2.3", {
23
+ * type: "deploy",
24
+ * title: "Release 1.2.3",
25
+ * description: "https://github.com/acme/app/releases/tag/v1.2.3",
26
+ * datasets: ["my-app-traces", "my-app-logs"],
27
+ * time: new Date().toISOString(),
28
+ * url: "https://github.com/acme/app/releases/tag/v1.2.3",
29
+ * });
30
+ * ```
31
+ *
32
+ * **Example:** Incident time-range
33
+ * ```typescript
34
+ * yield* Axiom.Annotation("inc-2026-04-27", {
35
+ * type: "incident",
36
+ * title: "Database failover",
37
+ * datasets: ["my-app-traces"],
38
+ * time: "2026-04-27T18:05:00Z",
39
+ * endTime: "2026-04-27T18:32:00Z",
40
+ * url: "https://incident.io/incidents/abc123",
41
+ * });
42
+ * ```
43
+ *
44
+ * @resource
45
+ * @product Dataset
46
+ */
47
+ export const Annotation = Resource("Axiom.Annotation");
48
+ export const AnnotationProvider = () => Provider.effect(Annotation, Effect.gen(function* () {
49
+ const create = yield* Axiom.createAnnotation;
50
+ const update = yield* Axiom.updateAnnotation;
51
+ const get = yield* Axiom.getAnnotation;
52
+ const del = yield* Axiom.deleteAnnotation;
53
+ const listAnnotations = yield* Axiom.getAnnotations;
54
+ return {
55
+ stables: ["id"],
56
+ // Axiom exposes a flat, account-wide `GET /v2/annotations` list that
57
+ // returns every annotation's full record in one (non-paginated)
58
+ // response — the exact same shape `get`/`read` produce. Hand each
59
+ // record back directly as the resource's Attributes.
60
+ list: () => listAnnotations({}).pipe(Effect.map((annotations) => annotations.map((a) => ({ ...a })))),
61
+ reconcile: Effect.fn(function* ({ news, output }) {
62
+ // Observe — Axiom assigns the annotation id server-side, so the
63
+ // only handle to a previously-created annotation is the cached
64
+ // `output.id`. Probe for live state with that id; treat NotFound
65
+ // (deleted out-of-band, or never created) as "no observed state".
66
+ const observed = output?.id
67
+ ? yield* get({ id: output.id }).pipe(Effect.catchTag("NotFound", () => Effect.succeed(undefined)))
68
+ : undefined;
69
+ // Ensure — when no observed annotation exists, POST creates one
70
+ // and Axiom assigns the id.
71
+ if (observed === undefined) {
72
+ return yield* create(news);
73
+ }
74
+ // Sync — the annotation exists; apply desired props with PUT and
75
+ // preserve the stable id and original time as fallbacks.
76
+ const result = yield* update({ ...news, id: observed.id });
77
+ return {
78
+ ...result,
79
+ id: observed.id,
80
+ time: result.time ?? output?.time ?? news.time,
81
+ };
82
+ }),
83
+ delete: Effect.fn(function* ({ output }) {
84
+ yield* del({ id: output.id }).pipe(Effect.catchTag("NotFound", () => Effect.void));
85
+ }),
86
+ read: Effect.fn(function* ({ output }) {
87
+ if (!output?.id)
88
+ return undefined;
89
+ return yield* get({ id: output.id }).pipe(Effect.map((current) => ({
90
+ ...current,
91
+ id: current.id ?? output.id,
92
+ time: current.time ?? output.time,
93
+ })), Effect.catchTag("NotFound", () => Effect.succeed(undefined)));
94
+ }),
95
+ };
96
+ }));
97
+ //# sourceMappingURL=Annotation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Annotation.js","sourceRoot":"","sources":["../src/Annotation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAaxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAa,kBAAkB,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE,CACrC,QAAQ,CAAC,MAAM,CACb,UAAU,EACV,MAAM,CAAC,GAAG,CA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AAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAC7D,CAAC;QACJ,CAAC,CAAC;KACH,CAAC;AACJ,CAAC,CAAC,CACH,CAAC"}
@@ -0,0 +1,64 @@
1
+ import * as Axiom from "@distilled.cloud/axiom";
2
+ import * as Provider from "alchemy/Provider";
3
+ import { Resource } from "alchemy/Resource";
4
+ import * as Redacted from "effect/Redacted";
5
+ import type { Providers } from "./Providers.ts";
6
+ export type ApiTokenProps = Omit<Axiom.CreateAPITokenRequest, never>;
7
+ export type ApiToken = Resource<"Axiom.ApiToken", ApiTokenProps, Omit<Axiom.CreateAPITokenResponse, "token"> & {
8
+ /**
9
+ * The bearer token. Returned only by `create` (and `regenerate`); Axiom
10
+ * does not return it on subsequent reads. Persisted in resource state via
11
+ * `Redacted` — handle with care.
12
+ */
13
+ token: Redacted.Redacted<string>;
14
+ }, never, Providers>;
15
+ /**
16
+ * An Axiom API token — a scoped bearer token used to authenticate API
17
+ * requests (ingest, query, admin). Capabilities are pinned at creation time;
18
+ * changing any field triggers a **replacement** because Axiom does not
19
+ * expose an update endpoint.
20
+ *
21
+ * The raw token value is returned only by `create`. After that, Axiom
22
+ * never echoes it back, so it is captured into `output.token` (as a
23
+ * {@link Redacted}) on initial create and persisted in resource state.
24
+ * Treat resource state as sensitive — anyone with read access can recover
25
+ * the token. Pair with a secret store for downstream consumption.
26
+ * @see https://axiom.co/docs/reference/tokens
27
+ *
28
+ * ### Creating an API Token
29
+ * **Example:** Ingest-only token scoped to one dataset
30
+ * ```typescript
31
+ * const ingest = yield* Axiom.ApiToken("ingest", {
32
+ * name: "prod-ingest",
33
+ * description: "OTEL collector ingest",
34
+ * datasetCapabilities: {
35
+ * "my-app-traces": { ingest: ["create"] },
36
+ * },
37
+ * });
38
+ * ```
39
+ *
40
+ * **Example:** Read-only query token
41
+ * ```typescript
42
+ * yield* Axiom.ApiToken("query", {
43
+ * name: "grafana-reader",
44
+ * datasetCapabilities: {
45
+ * "my-app-traces": { query: ["read"] },
46
+ * "my-app-logs": { query: ["read"] },
47
+ * },
48
+ * });
49
+ * ```
50
+ *
51
+ * ### Consuming the Token
52
+ * **Example:** Forward the token via Cloudflare Secrets
53
+ * ```typescript
54
+ * const secret = yield* Cloudflare.SecretsStore.Secret("axiom-token", {
55
+ * value: ingest.token,
56
+ * });
57
+ * ```
58
+ *
59
+ * @resource
60
+ * @product API Token
61
+ */
62
+ export declare const ApiToken: import("alchemy/Resource").ResourceClass<ApiToken>;
63
+ export declare const ApiTokenProvider: () => import("effect/Layer").Layer<Provider.Provider<ApiToken>, never, Axiom.AxiomOpContext>;
64
+ //# sourceMappingURL=ApiToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiToken.d.ts","sourceRoot":"","sources":["../src/ApiToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAEhD,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;AAErE,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAC7B,gBAAgB,EAChB,aAAa,EACb,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,OAAO,CAAC,GAAG;IAC5C;;;;OAIG;IACH,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;CAClC,EACD,KAAK,EACL,SAAS,CACV,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,QAAQ,oDAAuC,CAAC;AAE7D,eAAO,MAAM,gBAAgB,8FAyE1B,CAAC"}
@@ -0,0 +1,123 @@
1
+ import * as Axiom from "@distilled.cloud/axiom";
2
+ import { deepEqual, isResolved } from "alchemy/Diff";
3
+ import * as Provider from "alchemy/Provider";
4
+ import { Resource } from "alchemy/Resource";
5
+ import * as Effect from "effect/Effect";
6
+ import * as Redacted from "effect/Redacted";
7
+ /**
8
+ * An Axiom API token — a scoped bearer token used to authenticate API
9
+ * requests (ingest, query, admin). Capabilities are pinned at creation time;
10
+ * changing any field triggers a **replacement** because Axiom does not
11
+ * expose an update endpoint.
12
+ *
13
+ * The raw token value is returned only by `create`. After that, Axiom
14
+ * never echoes it back, so it is captured into `output.token` (as a
15
+ * {@link Redacted}) on initial create and persisted in resource state.
16
+ * Treat resource state as sensitive — anyone with read access can recover
17
+ * the token. Pair with a secret store for downstream consumption.
18
+ * @see https://axiom.co/docs/reference/tokens
19
+ *
20
+ * ### Creating an API Token
21
+ * **Example:** Ingest-only token scoped to one dataset
22
+ * ```typescript
23
+ * const ingest = yield* Axiom.ApiToken("ingest", {
24
+ * name: "prod-ingest",
25
+ * description: "OTEL collector ingest",
26
+ * datasetCapabilities: {
27
+ * "my-app-traces": { ingest: ["create"] },
28
+ * },
29
+ * });
30
+ * ```
31
+ *
32
+ * **Example:** Read-only query token
33
+ * ```typescript
34
+ * yield* Axiom.ApiToken("query", {
35
+ * name: "grafana-reader",
36
+ * datasetCapabilities: {
37
+ * "my-app-traces": { query: ["read"] },
38
+ * "my-app-logs": { query: ["read"] },
39
+ * },
40
+ * });
41
+ * ```
42
+ *
43
+ * ### Consuming the Token
44
+ * **Example:** Forward the token via Cloudflare Secrets
45
+ * ```typescript
46
+ * const secret = yield* Cloudflare.SecretsStore.Secret("axiom-token", {
47
+ * value: ingest.token,
48
+ * });
49
+ * ```
50
+ *
51
+ * @resource
52
+ * @product API Token
53
+ */
54
+ export const ApiToken = Resource("Axiom.ApiToken");
55
+ export const ApiTokenProvider = () => Provider.effect(ApiToken, Effect.gen(function* () {
56
+ const create = yield* Axiom.createAPIToken;
57
+ const get = yield* Axiom.getAPIToken;
58
+ const del = yield* Axiom.deleteAPIToken;
59
+ const listTokens = yield* Axiom.getAPITokens;
60
+ return {
61
+ stables: ["id", "token"],
62
+ // Enumerate every API token in the org. Axiom exposes a single
63
+ // account-wide `GET /v2/tokens` collection op (no pagination), so we
64
+ // fetch it once and hydrate each row into the exact `read` Attributes
65
+ // shape. The bearer secret is returned by Axiom only at creation and is
66
+ // never echoed back on enumeration, so — matching `read`, which sources
67
+ // the secret from cached state — we surface an empty Redacted token
68
+ // here rather than the real value.
69
+ list: () => Effect.gen(function* () {
70
+ const tokens = yield* listTokens({});
71
+ return tokens.map((token) => ({
72
+ ...token,
73
+ token: Redacted.make(""),
74
+ }));
75
+ }),
76
+ diff: Effect.fn(function* ({ olds, news, output }) {
77
+ if (!isResolved(news))
78
+ return undefined;
79
+ // First create — let the engine create normally.
80
+ if (output == null)
81
+ return undefined;
82
+ // Axiom has no update endpoint for tokens, so any actual change
83
+ // to the inputs forces a replacement (which mints a new bearer
84
+ // value). If nothing changed, fall through to `noop` so we don't
85
+ // needlessly rotate the token on every deploy.
86
+ if (deepEqual(olds, news))
87
+ return undefined;
88
+ return { action: "replace" };
89
+ }),
90
+ reconcile: Effect.fn(function* ({ news, output }) {
91
+ // Observe — Axiom does not expose an update endpoint for tokens,
92
+ // so any actual change to the inputs is forced to a replacement
93
+ // by `diff` above. That means by the time `reconcile` runs we
94
+ // are either (a) creating fresh, or (b) re-reconciling identical
95
+ // inputs against an existing token.
96
+ if (output !== undefined) {
97
+ // Identical inputs — Axiom does not echo the bearer back, so
98
+ // the cached `output` (with the persisted Redacted token) is
99
+ // the authoritative current state.
100
+ return output;
101
+ }
102
+ // Ensure — mint a new token. Axiom returns the bearer exactly
103
+ // once; capture it into Redacted state for downstream consumers.
104
+ const result = yield* create(news);
105
+ if (!result.token) {
106
+ return yield* Effect.die(new Error("Axiom did not return a token on create"));
107
+ }
108
+ return {
109
+ ...result,
110
+ token: Redacted.make(result.token),
111
+ };
112
+ }),
113
+ delete: Effect.fn(function* ({ output }) {
114
+ yield* del({ id: output.id }).pipe(Effect.catchTag("NotFound", () => Effect.void));
115
+ }),
116
+ read: Effect.fn(function* ({ output }) {
117
+ if (!output?.id)
118
+ return undefined;
119
+ return yield* get({ id: output.id }).pipe(Effect.map((current) => ({ ...current, token: output.token })), Effect.catchTag("NotFound", () => Effect.succeed(undefined)));
120
+ }),
121
+ };
122
+ }));
123
+ //# sourceMappingURL=ApiToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiToken.js","sourceRoot":"","sources":["../src/ApiToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAoB5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAW,gBAAgB,CAAC,CAAC;AAE7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CACnC,QAAQ,CAAC,MAAM,CACb,QAAQ,EACR,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC;IAC3C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC;IACrC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC;IACxC,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC;IAE7C,OAAO;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