@massdriver/backstage-plugin-backend 1.0.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/LICENSE +202 -0
- package/README.md +48 -0
- package/dist/absinthe.cjs.js +162 -0
- package/dist/absinthe.cjs.js.map +1 -0
- package/dist/index.cjs.js +10 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/plugin.cjs.js +24 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/router.cjs.js +138 -0
- package/dist/router.cjs.js.map +1 -0
- package/package.json +65 -0
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
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @massdriver/backstage-plugin-backend
|
|
2
|
+
|
|
3
|
+
Backend relay for the
|
|
4
|
+
[Massdriver Backstage plugin](https://www.npmjs.com/package/@massdriver/backstage-plugin).
|
|
5
|
+
It is the only component that holds Massdriver credentials:
|
|
6
|
+
|
|
7
|
+
- **`POST /api/massdriver/graphql`** — forwards read-only GraphQL queries to
|
|
8
|
+
the Massdriver v2 API, injecting the service-account token and your
|
|
9
|
+
`organizationId` server-side. The browser never sees the token, and
|
|
10
|
+
client-supplied organization IDs never win over the configured one.
|
|
11
|
+
- **`POST /api/massdriver/subscribe`** — bridges Massdriver's realtime
|
|
12
|
+
(Phoenix/Absinthe WebSocket) events to the browser as Server-Sent Events, so
|
|
13
|
+
the frontend stays live without holding credentials.
|
|
14
|
+
|
|
15
|
+
There are **no mutation endpoints** — the integration is read-only by design.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# From your Backstage repo root
|
|
21
|
+
yarn --cwd packages/backend add @massdriver/backstage-plugin-backend
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Then add it in `packages/backend/src/index.ts`:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
backend.add(import('@massdriver/backstage-plugin-backend'));
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Configuration
|
|
31
|
+
|
|
32
|
+
Reads the `massdriver` block from your app config — see the
|
|
33
|
+
[frontend plugin README](https://www.npmjs.com/package/@massdriver/backstage-plugin)
|
|
34
|
+
for the full reference, including where to find your organization ID and how
|
|
35
|
+
to mint a service-account token. Minimal setup:
|
|
36
|
+
|
|
37
|
+
```yaml
|
|
38
|
+
# app-config.yaml
|
|
39
|
+
massdriver:
|
|
40
|
+
organizationId: ${MASSDRIVER_ORG_ID}
|
|
41
|
+
apiToken: ${MASSDRIVER_API_TOKEN} # secret — backend only
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Deployment note
|
|
45
|
+
|
|
46
|
+
The backend needs outbound HTTPS **and WebSocket (WSS)** access to your
|
|
47
|
+
Massdriver API origin (`https://api.massdriver.cloud` by default, or your
|
|
48
|
+
`massdriver.baseUrl` if self-hosted) — WebSockets power the realtime bridge.
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var WebSocket = require('ws');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var WebSocket__default = /*#__PURE__*/_interopDefaultCompat(WebSocket);
|
|
8
|
+
|
|
9
|
+
const CONTROL_TOPIC = "__absinthe__:control";
|
|
10
|
+
const HEARTBEAT_INTERVAL_MS = 3e4;
|
|
11
|
+
const buildWebsocketUrl = (socketUrl, token) => {
|
|
12
|
+
const base = socketUrl.replace(/\/+$/, "");
|
|
13
|
+
const params = new URLSearchParams({ token, vsn: "2.0.0" });
|
|
14
|
+
return `${base}/websocket?${params.toString()}`;
|
|
15
|
+
};
|
|
16
|
+
const parsePhoenixMessage = (raw) => {
|
|
17
|
+
let parsed;
|
|
18
|
+
try {
|
|
19
|
+
parsed = JSON.parse(raw);
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (!Array.isArray(parsed) || parsed.length !== 5) return null;
|
|
24
|
+
const [joinRef, ref, topic, event, payload] = parsed;
|
|
25
|
+
if (typeof topic !== "string" || typeof event !== "string") return null;
|
|
26
|
+
return [
|
|
27
|
+
joinRef,
|
|
28
|
+
ref,
|
|
29
|
+
topic,
|
|
30
|
+
event,
|
|
31
|
+
payload ?? {}
|
|
32
|
+
];
|
|
33
|
+
};
|
|
34
|
+
const openAbsintheSubscription = (options) => {
|
|
35
|
+
const {
|
|
36
|
+
socketUrl,
|
|
37
|
+
token,
|
|
38
|
+
query,
|
|
39
|
+
variables,
|
|
40
|
+
onData,
|
|
41
|
+
onError,
|
|
42
|
+
onClose,
|
|
43
|
+
logger
|
|
44
|
+
} = options;
|
|
45
|
+
const createSocket = options.createSocket ?? ((url) => new WebSocket__default.default(url));
|
|
46
|
+
let ws;
|
|
47
|
+
try {
|
|
48
|
+
ws = createSocket(buildWebsocketUrl(socketUrl, token));
|
|
49
|
+
} catch (creationError) {
|
|
50
|
+
queueMicrotask(() => {
|
|
51
|
+
onError(creationError);
|
|
52
|
+
onClose?.();
|
|
53
|
+
});
|
|
54
|
+
return { close: () => {
|
|
55
|
+
} };
|
|
56
|
+
}
|
|
57
|
+
let refCounter = 0;
|
|
58
|
+
const nextRef = () => String(++refCounter);
|
|
59
|
+
const joinRef = nextRef();
|
|
60
|
+
let joinReplyRef = null;
|
|
61
|
+
let docRef = null;
|
|
62
|
+
let subscriptionId = null;
|
|
63
|
+
let heartbeat;
|
|
64
|
+
let awaitingHeartbeat = false;
|
|
65
|
+
let closed = false;
|
|
66
|
+
const send = (message) => {
|
|
67
|
+
if (ws.readyState === WebSocket__default.default.OPEN) ws.send(JSON.stringify(message));
|
|
68
|
+
};
|
|
69
|
+
const cleanup = () => {
|
|
70
|
+
if (heartbeat) clearInterval(heartbeat);
|
|
71
|
+
heartbeat = void 0;
|
|
72
|
+
};
|
|
73
|
+
const close = () => {
|
|
74
|
+
if (closed) return;
|
|
75
|
+
closed = true;
|
|
76
|
+
cleanup();
|
|
77
|
+
try {
|
|
78
|
+
if (ws.readyState === WebSocket__default.default.OPEN) {
|
|
79
|
+
send([joinRef, nextRef(), CONTROL_TOPIC, "phx_leave", {}]);
|
|
80
|
+
}
|
|
81
|
+
ws.close();
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
ws.on("open", () => {
|
|
86
|
+
joinReplyRef = nextRef();
|
|
87
|
+
send([joinRef, joinReplyRef, CONTROL_TOPIC, "phx_join", {}]);
|
|
88
|
+
heartbeat = setInterval(() => {
|
|
89
|
+
if (awaitingHeartbeat) {
|
|
90
|
+
logger?.debug?.("Absinthe socket heartbeat timed out; terminating");
|
|
91
|
+
ws.terminate();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
awaitingHeartbeat = true;
|
|
95
|
+
send([null, nextRef(), "phoenix", "heartbeat", {}]);
|
|
96
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
97
|
+
});
|
|
98
|
+
ws.on("message", (raw) => {
|
|
99
|
+
if (closed) return;
|
|
100
|
+
awaitingHeartbeat = false;
|
|
101
|
+
const message = parsePhoenixMessage(raw.toString());
|
|
102
|
+
if (!message) return;
|
|
103
|
+
const [, ref, topic, event, payload] = message;
|
|
104
|
+
if (event === "phx_reply") {
|
|
105
|
+
const status = payload.status;
|
|
106
|
+
const response = payload.response ?? {};
|
|
107
|
+
if (status === "error") {
|
|
108
|
+
const channelError = Object.assign(
|
|
109
|
+
new Error(
|
|
110
|
+
`Absinthe channel error: ${JSON.stringify(response) || "unknown"}`
|
|
111
|
+
),
|
|
112
|
+
{ fatal: true }
|
|
113
|
+
);
|
|
114
|
+
onError(channelError);
|
|
115
|
+
close();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (ref === joinReplyRef) {
|
|
119
|
+
docRef = nextRef();
|
|
120
|
+
send([joinRef, docRef, CONTROL_TOPIC, "doc", { query, variables }]);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (ref === docRef) {
|
|
124
|
+
const replySubscriptionId = response.subscriptionId;
|
|
125
|
+
if (replySubscriptionId) {
|
|
126
|
+
subscriptionId = replySubscriptionId;
|
|
127
|
+
} else if ("data" in response) {
|
|
128
|
+
onData(response.data);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (event === "subscription:data") {
|
|
135
|
+
const payloadSubscriptionId = payload.subscriptionId;
|
|
136
|
+
if (payloadSubscriptionId && subscriptionId && payloadSubscriptionId !== subscriptionId) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const result = payload.result ?? {};
|
|
140
|
+
onData(result.data);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (event === "phx_error" || event === "phx_close") {
|
|
144
|
+
logger?.debug?.(`Absinthe channel ${event} on ${topic}`);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
ws.on("error", (error) => {
|
|
148
|
+
logger?.error(`Absinthe socket error: ${error.message}`);
|
|
149
|
+
if (!closed) onError(error);
|
|
150
|
+
});
|
|
151
|
+
ws.on("close", () => {
|
|
152
|
+
cleanup();
|
|
153
|
+
closed = true;
|
|
154
|
+
onClose?.();
|
|
155
|
+
});
|
|
156
|
+
return { close };
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
exports.buildWebsocketUrl = buildWebsocketUrl;
|
|
160
|
+
exports.openAbsintheSubscription = openAbsintheSubscription;
|
|
161
|
+
exports.parsePhoenixMessage = parsePhoenixMessage;
|
|
162
|
+
//# sourceMappingURL=absinthe.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"absinthe.cjs.js","sources":["../src/absinthe.ts"],"sourcesContent":["import WebSocket from 'ws';\n\n/**\n * Minimal headless Absinthe-over-Phoenix subscription client.\n *\n * The Massdriver web app subscribes over a Phoenix/Absinthe WebSocket using\n * `@absinthe/socket` + `phoenix` in the browser. Those libraries assume a\n * browser environment, so rather than run them in Node we speak the Phoenix v2\n * channel protocol directly over `ws` — the same wire format their stack emits.\n *\n * Each client owns exactly one subscription: it connects, joins the Absinthe\n * control channel, pushes the subscription document, and forwards every\n * `subscription:data` payload to `onData`. The backend relay opens one of these\n * per browser SSE connection and streams the results down.\n *\n * The service-account token is passed as the socket's `token` query param\n * (mirroring the web app's `params: () => ({ token })`) and never leaves the\n * backend.\n */\n\n// Phoenix v2 serializer frames every message as a positional tuple:\n// [join_ref, ref, topic, event, payload].\ntype PhoenixMessage = [\n string | null,\n string | null,\n string,\n string,\n Record<string, unknown>,\n];\n\nconst CONTROL_TOPIC = '__absinthe__:control';\nconst HEARTBEAT_INTERVAL_MS = 30_000;\n\n/**\n * Build the raw WebSocket URL from the socket endpoint. Phoenix appends\n * `/websocket` to the endpoint and takes connection params (here, the auth\n * token and the serializer version) as query string.\n */\nexport const buildWebsocketUrl = (socketUrl: string, token: string): string => {\n const base = socketUrl.replace(/\\/+$/, '');\n const params = new URLSearchParams({ token, vsn: '2.0.0' });\n return `${base}/websocket?${params.toString()}`;\n};\n\n/**\n * Parse a raw Phoenix frame. Returns null when the payload is not a well-formed\n * v2 tuple (so a malformed/heartbeat-only frame is ignored rather than throwing).\n */\nexport const parsePhoenixMessage = (raw: string): PhoenixMessage | null => {\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return null;\n }\n if (!Array.isArray(parsed) || parsed.length !== 5) return null;\n const [joinRef, ref, topic, event, payload] = parsed as unknown[];\n if (typeof topic !== 'string' || typeof event !== 'string') return null;\n return [\n joinRef as string | null,\n ref as string | null,\n topic,\n event,\n (payload ?? {}) as Record<string, unknown>,\n ];\n};\n\n/**\n * Errors from a channel-level `phx_reply` with `status: 'error'` (join or doc\n * rejection — bad token, invalid document, unknown environment) carry\n * `fatal: true`: retrying with the same inputs cannot succeed, so the frontend\n * stops reconnecting. Transport errors stay retryable (no flag).\n */\nexport type AbsintheSubscriptionError = Error & { fatal?: boolean };\n\nexport interface AbsintheSubscriptionOptions {\n /** Socket endpoint, e.g. `wss://api.massdriver.cloud/api/socket`. */\n socketUrl: string;\n /** Service-account bearer token (query param, backend-only). */\n token: string;\n /** Subscription document. */\n query: string;\n /** Operation variables (`organizationId` is injected by the caller). */\n variables?: Record<string, unknown>;\n /** Called with `result.data` for each streamed `subscription:data`. */\n onData: (data: unknown) => void;\n /** Called on a transport/protocol error. */\n onError: (error: AbsintheSubscriptionError) => void;\n /** Called once the socket closes (after `onError`, if any). */\n onClose?: () => void;\n logger?: {\n error: (message: string) => void;\n debug?: (message: string) => void;\n };\n /** Socket factory — injection seam for tests. Defaults to `new WebSocket(url)`. */\n createSocket?: (url: string) => WebSocket;\n}\n\n/** A live subscription handle; call `close()` to tear it down. */\nexport interface AbsintheSubscription {\n close: () => void;\n}\n\n/**\n * Open a single Absinthe subscription and stream its results to `onData`.\n * Returns a handle whose `close()` leaves the channel and closes the socket.\n */\nexport const openAbsintheSubscription = (\n options: AbsintheSubscriptionOptions,\n): AbsintheSubscription => {\n const {\n socketUrl,\n token,\n query,\n variables,\n onData,\n onError,\n onClose,\n logger,\n } = options;\n const createSocket = options.createSocket ?? (url => new WebSocket(url));\n\n let ws: WebSocket;\n try {\n ws = createSocket(buildWebsocketUrl(socketUrl, token));\n } catch (creationError) {\n // Fail asynchronously so the caller has its handle (and, for the SSE\n // relay, its already-flushed headers) before the error lands.\n queueMicrotask(() => {\n onError(creationError as Error);\n onClose?.();\n });\n return { close: () => {} };\n }\n\n let refCounter = 0;\n const nextRef = () => String(++refCounter);\n const joinRef = nextRef();\n let joinReplyRef: string | null = null;\n let docRef: string | null = null;\n // The `__absinthe__:doc:<hash>` subscription id from the doc reply.\n let subscriptionId: string | null = null;\n let heartbeat: ReturnType<typeof setInterval> | undefined;\n let awaitingHeartbeat = false;\n let closed = false;\n\n const send = (message: PhoenixMessage) => {\n if (ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify(message));\n };\n\n const cleanup = () => {\n if (heartbeat) clearInterval(heartbeat);\n heartbeat = undefined;\n };\n\n const close = () => {\n if (closed) return;\n closed = true;\n cleanup();\n // Best-effort leave; ignore if the socket is already gone.\n try {\n if (ws.readyState === WebSocket.OPEN) {\n send([joinRef, nextRef(), CONTROL_TOPIC, 'phx_leave', {}]);\n }\n ws.close();\n } catch {\n /* already closing */\n }\n };\n\n ws.on('open', () => {\n joinReplyRef = nextRef();\n send([joinRef, joinReplyRef, CONTROL_TOPIC, 'phx_join', {}]);\n heartbeat = setInterval(() => {\n // A heartbeat interval elapsing with no traffic since the last one means\n // the connection is half-open — terminate so 'close' fires and the\n // frontend's reconnect loop takes over.\n if (awaitingHeartbeat) {\n logger?.debug?.('Absinthe socket heartbeat timed out; terminating');\n ws.terminate();\n return;\n }\n awaitingHeartbeat = true;\n send([null, nextRef(), 'phoenix', 'heartbeat', {}]);\n }, HEARTBEAT_INTERVAL_MS);\n });\n\n ws.on('message', (raw: WebSocket.RawData) => {\n if (closed) return;\n awaitingHeartbeat = false; // any traffic proves liveness\n const message = parsePhoenixMessage(raw.toString());\n if (!message) return;\n const [, ref, topic, event, payload] = message;\n\n if (event === 'phx_reply') {\n const status = payload.status as string | undefined;\n const response = (payload.response ?? {}) as Record<string, unknown>;\n\n if (status === 'error') {\n // A channel-level rejection (bad token, invalid doc, unknown\n // environment) won't succeed on retry — mark it fatal so the\n // frontend stops reconnecting.\n const channelError: AbsintheSubscriptionError = Object.assign(\n new Error(\n `Absinthe channel error: ${JSON.stringify(response) || 'unknown'}`,\n ),\n { fatal: true },\n );\n onError(channelError);\n close();\n return;\n }\n\n // Join succeeded → push the subscription document.\n if (ref === joinReplyRef) {\n docRef = nextRef();\n send([joinRef, docRef, CONTROL_TOPIC, 'doc', { query, variables }]);\n return;\n }\n\n // Document accepted → remember the subscription id.\n if (ref === docRef) {\n const replySubscriptionId = response.subscriptionId as\n | string\n | undefined;\n if (replySubscriptionId) {\n subscriptionId = replySubscriptionId;\n } else if ('data' in response) {\n // A non-subscription document (query/mutation) resolves inline.\n onData(response.data);\n }\n return;\n }\n return;\n }\n\n if (event === 'subscription:data') {\n // Mirror `@absinthe/socket`: match on the event alone and correlate by\n // the payload's subscriptionId when both sides carry one. Each socket\n // owns exactly one subscription, so a topic check adds only fragility\n // (a framing change upstream would silently drop every event).\n const payloadSubscriptionId = payload.subscriptionId as\n | string\n | undefined;\n if (\n payloadSubscriptionId &&\n subscriptionId &&\n payloadSubscriptionId !== subscriptionId\n ) {\n return;\n }\n const result = (payload.result ?? {}) as { data?: unknown };\n onData(result.data);\n return;\n }\n\n if (event === 'phx_error' || event === 'phx_close') {\n logger?.debug?.(`Absinthe channel ${event} on ${topic}`);\n }\n });\n\n ws.on('error', (error: Error) => {\n logger?.error(`Absinthe socket error: ${error.message}`);\n if (!closed) onError(error);\n });\n\n ws.on('close', () => {\n cleanup();\n closed = true;\n onClose?.();\n });\n\n return { close };\n};\n"],"names":["WebSocket"],"mappings":";;;;;;;;AA8BA,MAAM,aAAA,GAAgB,sBAAA;AACtB,MAAM,qBAAA,GAAwB,GAAA;AAOvB,MAAM,iBAAA,GAAoB,CAAC,SAAA,EAAmB,KAAA,KAA0B;AAC7E,EAAA,MAAM,IAAA,GAAO,SAAA,CAAU,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AACzC,EAAA,MAAM,SAAS,IAAI,eAAA,CAAgB,EAAE,KAAA,EAAO,GAAA,EAAK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A,IAAI,CAAC,MAAA,EAAQ,OAAA,CAAQ,KAAK,CAAA;AAAA,EAC5B,CAAC,CAAA;AAED,EAAA,EAAA,CAAG,EAAA,CAAG,SAAS,MAAM;AACnB,IAAA,OAAA,EAAQ;AACR,IAAA,MAAA,GAAS,IAAA;AACT,IAAA,OAAA,IAAU;AAAA,EACZ,CAAC,CAAA;AAED,EAAA,OAAO,EAAE,KAAA,EAAM;AACjB;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Massdriver backend plugin.
|
|
5
|
+
*
|
|
6
|
+
* Exposes an authenticated GraphQL relay at `/api/massdriver/graphql` that
|
|
7
|
+
* forwards queries to the Massdriver v2 API with a service-account bearer token
|
|
8
|
+
* injected server-side. The token is read from config and never reaches the
|
|
9
|
+
* browser.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
declare const massdriverPlugin: _backstage_backend_plugin_api.BackendFeature;
|
|
14
|
+
|
|
15
|
+
export { massdriverPlugin as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var router = require('./router.cjs.js');
|
|
5
|
+
|
|
6
|
+
const massdriverPlugin = backendPluginApi.createBackendPlugin({
|
|
7
|
+
pluginId: "massdriver",
|
|
8
|
+
register(env) {
|
|
9
|
+
env.registerInit({
|
|
10
|
+
deps: {
|
|
11
|
+
logger: backendPluginApi.coreServices.logger,
|
|
12
|
+
config: backendPluginApi.coreServices.rootConfig,
|
|
13
|
+
httpAuth: backendPluginApi.coreServices.httpAuth,
|
|
14
|
+
httpRouter: backendPluginApi.coreServices.httpRouter
|
|
15
|
+
},
|
|
16
|
+
async init({ logger, config, httpAuth, httpRouter }) {
|
|
17
|
+
httpRouter.use(await router.createRouter({ logger, config, httpAuth }));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
exports.massdriverPlugin = massdriverPlugin;
|
|
24
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.ts"],"sourcesContent":["import {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './router';\n\n/**\n * Massdriver backend plugin.\n *\n * Exposes an authenticated GraphQL relay at `/api/massdriver/graphql` that\n * forwards queries to the Massdriver v2 API with a service-account bearer token\n * injected server-side. The token is read from config and never reaches the\n * browser.\n *\n * @public\n */\nexport const massdriverPlugin = createBackendPlugin({\n pluginId: 'massdriver',\n register(env) {\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n },\n async init({ logger, config, httpAuth, httpRouter }) {\n httpRouter.use(await createRouter({ logger, config, httpAuth }));\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","createRouter"],"mappings":";;;;;AAgBO,MAAM,mBAAmBA,oCAAA,CAAoB;AAAA,EAClD,QAAA,EAAU,YAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,QAAQC,6BAAA,CAAa,MAAA;AAAA,QACrB,QAAQA,6BAAA,CAAa,UAAA;AAAA,QACrB,UAAUA,6BAAA,CAAa,QAAA;AAAA,QACvB,YAAYA,6BAAA,CAAa;AAAA,OAC3B;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,QAAQ,MAAA,EAAQ,QAAA,EAAU,YAAW,EAAG;AACnD,QAAA,UAAA,CAAW,GAAA,CAAI,MAAMC,mBAAA,CAAa,EAAE,QAAQ,MAAA,EAAQ,QAAA,EAAU,CAAC,CAAA;AAAA,MACjE;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var errors = require('@backstage/errors');
|
|
4
|
+
var backstagePluginCommon = require('@massdriver/backstage-plugin-common');
|
|
5
|
+
var express = require('express');
|
|
6
|
+
var Router = require('express-promise-router');
|
|
7
|
+
var absinthe = require('./absinthe.cjs.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var express__default = /*#__PURE__*/_interopDefaultCompat(express);
|
|
12
|
+
var Router__default = /*#__PURE__*/_interopDefaultCompat(Router);
|
|
13
|
+
|
|
14
|
+
const SSE_KEEPALIVE_MS = 25e3;
|
|
15
|
+
async function createRouter({
|
|
16
|
+
config,
|
|
17
|
+
logger,
|
|
18
|
+
httpAuth
|
|
19
|
+
}) {
|
|
20
|
+
let settings;
|
|
21
|
+
const getConfig = () => {
|
|
22
|
+
if (!settings) {
|
|
23
|
+
settings = backstagePluginCommon.readMassdriverConfig(config);
|
|
24
|
+
logger.info(
|
|
25
|
+
`Massdriver relay initialised for organization "${settings.organizationId}"`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return settings;
|
|
29
|
+
};
|
|
30
|
+
let client;
|
|
31
|
+
const getClient = () => {
|
|
32
|
+
if (!client) {
|
|
33
|
+
const { organizationId, apiToken, baseUrl } = getConfig();
|
|
34
|
+
client = backstagePluginCommon.createMassdriverClient({
|
|
35
|
+
token: apiToken,
|
|
36
|
+
organizationId,
|
|
37
|
+
baseUrl
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return client;
|
|
41
|
+
};
|
|
42
|
+
const router = Router__default.default();
|
|
43
|
+
router.use(express__default.default.json());
|
|
44
|
+
router.post("/graphql", async (req, res) => {
|
|
45
|
+
await httpAuth.credentials(req, { allow: ["user"] });
|
|
46
|
+
const { query, variables } = req.body ?? {};
|
|
47
|
+
if (typeof query !== "string" || !query.trim()) {
|
|
48
|
+
throw new errors.InputError(
|
|
49
|
+
"Request body must include a non-empty `query` string"
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const data = await getClient().query(query, variables);
|
|
53
|
+
res.json({ data });
|
|
54
|
+
});
|
|
55
|
+
router.get("/content", async (req, res) => {
|
|
56
|
+
await httpAuth.credentials(req, { allow: ["user"] });
|
|
57
|
+
const { url } = req.query;
|
|
58
|
+
if (typeof url !== "string" || !url) {
|
|
59
|
+
throw new errors.InputError("A `url` query parameter is required");
|
|
60
|
+
}
|
|
61
|
+
const { apiToken, baseUrl } = getConfig();
|
|
62
|
+
const apiOrigin = new URL(backstagePluginCommon.graphqlUrl(baseUrl)).origin;
|
|
63
|
+
let target;
|
|
64
|
+
try {
|
|
65
|
+
target = new URL(url);
|
|
66
|
+
} catch {
|
|
67
|
+
throw new errors.InputError("`url` must be an absolute URL");
|
|
68
|
+
}
|
|
69
|
+
if (target.origin !== apiOrigin) {
|
|
70
|
+
throw new errors.InputError(
|
|
71
|
+
`\`url\` must be on the Massdriver API origin (${apiOrigin})`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const upstream = await fetch(target, {
|
|
75
|
+
headers: { Authorization: `Bearer ${apiToken}` }
|
|
76
|
+
});
|
|
77
|
+
res.status(upstream.status);
|
|
78
|
+
const contentType = upstream.headers.get("content-type");
|
|
79
|
+
if (contentType) res.setHeader("Content-Type", contentType);
|
|
80
|
+
res.send(Buffer.from(await upstream.arrayBuffer()));
|
|
81
|
+
});
|
|
82
|
+
router.post("/subscribe", async (req, res) => {
|
|
83
|
+
await httpAuth.credentials(req, { allow: ["user"] });
|
|
84
|
+
const { query, variables } = req.body ?? {};
|
|
85
|
+
if (typeof query !== "string" || !query.trim()) {
|
|
86
|
+
throw new errors.InputError(
|
|
87
|
+
"Request body must include a non-empty `query` string"
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const { organizationId, apiToken, baseUrl } = getConfig();
|
|
91
|
+
res.writeHead(200, {
|
|
92
|
+
"Content-Type": "text/event-stream",
|
|
93
|
+
"Cache-Control": "no-cache, no-transform",
|
|
94
|
+
Connection: "keep-alive",
|
|
95
|
+
// Disable proxy buffering (nginx) so events flush immediately.
|
|
96
|
+
"X-Accel-Buffering": "no"
|
|
97
|
+
});
|
|
98
|
+
res.flushHeaders?.();
|
|
99
|
+
const write = (event, data) => {
|
|
100
|
+
if (res.writableEnded) return;
|
|
101
|
+
if (event) res.write(`event: ${event}
|
|
102
|
+
`);
|
|
103
|
+
res.write(`data: ${JSON.stringify(data)}
|
|
104
|
+
|
|
105
|
+
`);
|
|
106
|
+
};
|
|
107
|
+
const keepalive = setInterval(() => {
|
|
108
|
+
if (!res.writableEnded) res.write(": ping\n\n");
|
|
109
|
+
}, SSE_KEEPALIVE_MS);
|
|
110
|
+
const subscription = absinthe.openAbsintheSubscription({
|
|
111
|
+
socketUrl: backstagePluginCommon.socketUrl(baseUrl),
|
|
112
|
+
token: apiToken,
|
|
113
|
+
query,
|
|
114
|
+
// Server-injected org id must win over request variables.
|
|
115
|
+
variables: { ...variables ?? {}, organizationId },
|
|
116
|
+
logger,
|
|
117
|
+
onData: (data) => write(null, data),
|
|
118
|
+
onError: (error) => {
|
|
119
|
+
write("error", { message: error.message, fatal: Boolean(error.fatal) });
|
|
120
|
+
teardown();
|
|
121
|
+
},
|
|
122
|
+
onClose: () => teardown()
|
|
123
|
+
});
|
|
124
|
+
let torndown = false;
|
|
125
|
+
function teardown() {
|
|
126
|
+
if (torndown) return;
|
|
127
|
+
torndown = true;
|
|
128
|
+
clearInterval(keepalive);
|
|
129
|
+
subscription.close();
|
|
130
|
+
if (!res.writableEnded) res.end();
|
|
131
|
+
}
|
|
132
|
+
res.on("close", teardown);
|
|
133
|
+
});
|
|
134
|
+
return router;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
exports.createRouter = createRouter;
|
|
138
|
+
//# sourceMappingURL=router.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.cjs.js","sources":["../src/router.ts"],"sourcesContent":["import {\n HttpAuthService,\n LoggerService,\n RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport {\n createMassdriverClient,\n graphqlUrl,\n MassdriverClient,\n MassdriverConfig,\n readMassdriverConfig,\n socketUrl,\n} from '@massdriver/backstage-plugin-common';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { openAbsintheSubscription } from './absinthe';\n\n// Keep the downstream SSE connection (and any intermediary proxies) alive\n// between events. The upstream Absinthe socket has its own heartbeat.\nconst SSE_KEEPALIVE_MS = 25_000;\n\n/**\n * Builds the Massdriver relay router.\n *\n * The client is created lazily on first use so the backend still boots when the\n * plugin is installed but not yet configured — misconfiguration surfaces as a\n * request error rather than a startup crash.\n */\nexport async function createRouter({\n config,\n logger,\n httpAuth,\n}: {\n config: RootConfigService;\n logger: LoggerService;\n httpAuth: HttpAuthService;\n}): Promise<express.Router> {\n let settings: MassdriverConfig | undefined;\n const getConfig = (): MassdriverConfig => {\n if (!settings) {\n settings = readMassdriverConfig(config);\n logger.info(\n `Massdriver relay initialised for organization \"${settings.organizationId}\"`,\n );\n }\n return settings;\n };\n\n let client: MassdriverClient | undefined;\n const getClient = (): MassdriverClient => {\n if (!client) {\n const { organizationId, apiToken, baseUrl } = getConfig();\n client = createMassdriverClient({\n token: apiToken,\n organizationId,\n baseUrl,\n });\n }\n return client;\n };\n\n const router = Router();\n router.use(express.json());\n\n router.post('/graphql', async (req, res) => {\n // Require an authenticated Backstage user; the relay then queries with the\n // org's service-account token (org-wide read access — see plugin README).\n await httpAuth.credentials(req, { allow: ['user'] });\n\n const { query, variables } = (req.body ?? {}) as {\n query?: unknown;\n variables?: Record<string, unknown>;\n };\n\n if (typeof query !== 'string' || !query.trim()) {\n throw new InputError(\n 'Request body must include a non-empty `query` string',\n );\n }\n\n const data = await getClient().query(query, variables);\n res.json({ data });\n });\n\n // Authenticated content proxy. The web app fetches auth-guarded assets (OCI\n // repo icon SVGs, repo tag file contents) directly with the browser's bearer\n // token; this plugin's browser holds no token, so the backend fetches with\n // the service-account token instead. Locked to the configured Massdriver API\n // origin so this can't be used as an open proxy.\n router.get('/content', async (req, res) => {\n await httpAuth.credentials(req, { allow: ['user'] });\n\n const { url } = req.query as { url?: unknown };\n if (typeof url !== 'string' || !url) {\n throw new InputError('A `url` query parameter is required');\n }\n\n const { apiToken, baseUrl } = getConfig();\n const apiOrigin = new URL(graphqlUrl(baseUrl)).origin;\n\n let target: URL;\n try {\n target = new URL(url);\n } catch {\n throw new InputError('`url` must be an absolute URL');\n }\n if (target.origin !== apiOrigin) {\n throw new InputError(\n `\\`url\\` must be on the Massdriver API origin (${apiOrigin})`,\n );\n }\n\n const upstream = await fetch(target, {\n headers: { Authorization: `Bearer ${apiToken}` },\n });\n\n res.status(upstream.status);\n const contentType = upstream.headers.get('content-type');\n if (contentType) res.setHeader('Content-Type', contentType);\n res.send(Buffer.from(await upstream.arrayBuffer()));\n });\n\n // Server-Sent Events relay for GraphQL subscriptions. The browser cannot open\n // the Massdriver Absinthe socket directly (it holds no token), so the backend\n // opens it with the service-account token and streams each result down as an\n // SSE `data:` frame. `organizationId` is injected server-side, mirroring the\n // `/graphql` relay, so callers only declare `$organizationId` in the document.\n router.post('/subscribe', async (req, res) => {\n await httpAuth.credentials(req, { allow: ['user'] });\n\n const { query, variables } = (req.body ?? {}) as {\n query?: unknown;\n variables?: Record<string, unknown>;\n };\n\n if (typeof query !== 'string' || !query.trim()) {\n throw new InputError(\n 'Request body must include a non-empty `query` string',\n );\n }\n\n const { organizationId, apiToken, baseUrl } = getConfig();\n\n res.writeHead(200, {\n 'Content-Type': 'text/event-stream',\n 'Cache-Control': 'no-cache, no-transform',\n Connection: 'keep-alive',\n // Disable proxy buffering (nginx) so events flush immediately.\n 'X-Accel-Buffering': 'no',\n });\n res.flushHeaders?.();\n\n const write = (event: string | null, data: unknown) => {\n if (res.writableEnded) return;\n if (event) res.write(`event: ${event}\\n`);\n res.write(`data: ${JSON.stringify(data)}\\n\\n`);\n };\n\n const keepalive = setInterval(() => {\n if (!res.writableEnded) res.write(': ping\\n\\n');\n }, SSE_KEEPALIVE_MS);\n\n const subscription = openAbsintheSubscription({\n socketUrl: socketUrl(baseUrl),\n token: apiToken,\n query,\n // Server-injected org id must win over request variables.\n variables: { ...(variables ?? {}), organizationId },\n logger,\n onData: data => write(null, data),\n onError: error => {\n // `fatal` marks channel-level rejections (bad token/doc/environment)\n // that retrying cannot fix — the frontend stops reconnecting on it.\n write('error', { message: error.message, fatal: Boolean(error.fatal) });\n teardown();\n },\n onClose: () => teardown(),\n });\n\n let torndown = false;\n function teardown() {\n if (torndown) return;\n torndown = true;\n clearInterval(keepalive);\n subscription.close();\n if (!res.writableEnded) res.end();\n }\n\n // Browser navigated away / closed the EventSource-style reader. The\n // response 'close' event is the reliable disconnect signal — the request\n // readable closes as soon as the JSON body is consumed, long before the\n // client goes away.\n res.on('close', teardown);\n });\n\n return router;\n}\n"],"names":["readMassdriverConfig","createMassdriverClient","Router","express","InputError","graphqlUrl","openAbsintheSubscription","socketUrl"],"mappings":";;;;;;;;;;;;;AAoBA,MAAM,gBAAA,GAAmB,IAAA;AASzB,eAAsB,YAAA,CAAa;AAAA,EACjC,MAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,EAI4B;AAC1B,EAAA,IAAI,QAAA;AACJ,EAAA,MAAM,YAAY,MAAwB;AACxC,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAA,QAAA,GAAWA,2CAAqB,MAAM,CAAA;AACtC,MAAA,MAAA,CAAO,IAAA;AAAA,Q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EAAO,QAAA;AAAA,MACP,KAAA;AAAA;AAAA,MAEA,WAAW,EAAE,GAAI,SAAA,IAAa,IAAK,cAAA,EAAe;AAAA,MAClD,MAAA;AAAA,MACA,MAAA,EAAQ,CAAA,IAAA,KAAQ,KAAA,CAAM,IAAA,EAAM,IAAI,CAAA;AAAA,MAChC,SAAS,CAAA,KAAA,KAAS;AAGhB,QAAA,KAAA,CAAM,OAAA,EAAS,EAAE,OAAA,EAAS,KAAA,CAAM,OAAA,EAAS,OAAO,OAAA,CAAQ,KAAA,CAAM,KAAK,CAAA,EAAG,CAAA;AACtE,QAAA,QAAA,EAAS;AAAA,MACX,CAAA;AAAA,MACA,OAAA,EAAS,MAAM,QAAA;AAAS,KACzB,CAAA;AAED,IAAA,IAAI,QAAA,GAAW,KAAA;AACf,IAAA,SAAS,QAAA,GAAW;AAClB,MAAA,IAAI,QAAA,EAAU;AACd,MAAA,QAAA,GAAW,IAAA;AACX,MAAA,aAAA,CAAc,SAAS,CAAA;AACvB,MAAA,YAAA,CAAa,KAAA,EAAM;AACnB,MAAA,IAAI,CAAC,GAAA,CAAI,aAAA,EAAe,GAAA,CAAI,GAAA,EAAI;AAAA,IAClC;AAMA,IAAA,GAAA,CAAI,EAAA,CAAG,SAAS,QAAQ,CAAA;AAAA,EAC1B,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@massdriver/backstage-plugin-backend",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/massdriver-cloud/massdriver-backstage",
|
|
8
|
+
"directory": "plugins/massdriver-backend"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/index.cjs.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public",
|
|
14
|
+
"main": "dist/index.cjs.js",
|
|
15
|
+
"types": "dist/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"backstage": {
|
|
18
|
+
"role": "backend-plugin",
|
|
19
|
+
"pluginId": "massdriver",
|
|
20
|
+
"pluginPackages": [
|
|
21
|
+
"@massdriver/backstage-plugin",
|
|
22
|
+
"@massdriver/backstage-plugin-backend",
|
|
23
|
+
"@massdriver/backstage-plugin-common"
|
|
24
|
+
],
|
|
25
|
+
"features": {
|
|
26
|
+
".": "@backstage/BackendFeature"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"start": "backstage-cli package start",
|
|
31
|
+
"build": "backstage-cli package build",
|
|
32
|
+
"lint": "backstage-cli package lint",
|
|
33
|
+
"test": "backstage-cli package test",
|
|
34
|
+
"clean": "backstage-cli package clean",
|
|
35
|
+
"prepack": "backstage-cli package prepack",
|
|
36
|
+
"postpack": "backstage-cli package postpack"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@backstage/backend-defaults": "^0.17.3",
|
|
40
|
+
"@backstage/backend-plugin-api": "^1.9.2",
|
|
41
|
+
"@backstage/errors": "^1.3.1",
|
|
42
|
+
"@massdriver/backstage-plugin-common": "^1.0.0",
|
|
43
|
+
"express": "^4.14.0",
|
|
44
|
+
"express-promise-router": "^4.1.0",
|
|
45
|
+
"ws": "^8.18.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@backstage/backend-test-utils": "^1.11.4",
|
|
49
|
+
"@backstage/cli": "^0.36.3",
|
|
50
|
+
"@types/express": "^4.17.6",
|
|
51
|
+
"@types/supertest": "^2.0.12",
|
|
52
|
+
"@types/ws": "^8.5.10",
|
|
53
|
+
"supertest": "^6.2.4"
|
|
54
|
+
},
|
|
55
|
+
"files": [
|
|
56
|
+
"dist"
|
|
57
|
+
],
|
|
58
|
+
"typesVersions": {
|
|
59
|
+
"*": {
|
|
60
|
+
"package.json": [
|
|
61
|
+
"package.json"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|