@massdriver/backstage-plugin-common 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 +21 -0
- package/dist/annotations.cjs.js +12 -0
- package/dist/annotations.cjs.js.map +1 -0
- package/dist/annotations.esm.js +7 -0
- package/dist/annotations.esm.js.map +1 -0
- package/dist/client.cjs.js +57 -0
- package/dist/client.cjs.js.map +1 -0
- package/dist/client.esm.js +54 -0
- package/dist/client.esm.js.map +1 -0
- package/dist/config.cjs.js +25 -0
- package/dist/config.cjs.js.map +1 -0
- package/dist/config.esm.js +21 -0
- package/dist/config.esm.js.map +1 -0
- package/dist/index.cjs.js +43 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +317 -0
- package/dist/index.esm.js +5 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/urls.cjs.js +90 -0
- package/dist/urls.cjs.js.map +1 -0
- package/dist/urls.esm.js +65 -0
- package/dist/urls.esm.js.map +1 -0
- package/package.json +55 -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,21 @@
|
|
|
1
|
+
# @massdriver/backstage-plugin-common
|
|
2
|
+
|
|
3
|
+
Shared isomorphic library for the
|
|
4
|
+
[Massdriver Backstage plugin](https://www.npmjs.com/package/@massdriver/backstage-plugin)
|
|
5
|
+
and its
|
|
6
|
+
[backend relay](https://www.npmjs.com/package/@massdriver/backstage-plugin-backend).
|
|
7
|
+
You normally don't install this directly — it comes in as a dependency of the
|
|
8
|
+
other two packages.
|
|
9
|
+
|
|
10
|
+
It contains:
|
|
11
|
+
|
|
12
|
+
- **Catalog annotation keys** (`massdriver.cloud/project-id`,
|
|
13
|
+
`massdriver.cloud/environment-id`, `massdriver.cloud/instance-id`,
|
|
14
|
+
`massdriver.cloud/org-id`) for linking Backstage entities to Massdriver
|
|
15
|
+
resources.
|
|
16
|
+
- **Config schema and readers** for the `massdriver` app-config block
|
|
17
|
+
(`organizationId`, `apiToken`, `baseUrl`, `appUrl`), including the
|
|
18
|
+
visibility declarations that keep `apiToken` backend-only.
|
|
19
|
+
- **ID and deep-link helpers** — parsing Massdriver composite IDs and building
|
|
20
|
+
URLs into the Massdriver web app.
|
|
21
|
+
- The server-side GraphQL client used by the backend relay.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ANNOTATION_ORG_ID = "massdriver.cloud/org-id";
|
|
4
|
+
const ANNOTATION_PROJECT_ID = "massdriver.cloud/project-id";
|
|
5
|
+
const ANNOTATION_ENVIRONMENT_ID = "massdriver.cloud/environment-id";
|
|
6
|
+
const ANNOTATION_INSTANCE_ID = "massdriver.cloud/instance-id";
|
|
7
|
+
|
|
8
|
+
exports.ANNOTATION_ENVIRONMENT_ID = ANNOTATION_ENVIRONMENT_ID;
|
|
9
|
+
exports.ANNOTATION_INSTANCE_ID = ANNOTATION_INSTANCE_ID;
|
|
10
|
+
exports.ANNOTATION_ORG_ID = ANNOTATION_ORG_ID;
|
|
11
|
+
exports.ANNOTATION_PROJECT_ID = ANNOTATION_PROJECT_ID;
|
|
12
|
+
//# sourceMappingURL=annotations.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.cjs.js","sources":["../src/annotations.ts"],"sourcesContent":["/**\n * Catalog annotations that link a Backstage entity to a Massdriver resource.\n *\n * Frontend components render Massdriver UI only when the relevant annotation is\n * present on an entity. Add them to your own `catalog-info.yaml` to link an\n * entity to a Massdriver project, environment, or instance.\n *\n * @public\n */\nexport const ANNOTATION_ORG_ID = 'massdriver.cloud/org-id';\n\n/** @public */\nexport const ANNOTATION_PROJECT_ID = 'massdriver.cloud/project-id';\n\n/** @public */\nexport const ANNOTATION_ENVIRONMENT_ID = 'massdriver.cloud/environment-id';\n\n/** @public */\nexport const ANNOTATION_INSTANCE_ID = 'massdriver.cloud/instance-id';\n"],"names":[],"mappings":";;AASO,MAAM,iBAAA,GAAoB;AAG1B,MAAM,qBAAA,GAAwB;AAG9B,MAAM,yBAAA,GAA4B;AAGlC,MAAM,sBAAA,GAAyB;;;;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const ANNOTATION_ORG_ID = "massdriver.cloud/org-id";
|
|
2
|
+
const ANNOTATION_PROJECT_ID = "massdriver.cloud/project-id";
|
|
3
|
+
const ANNOTATION_ENVIRONMENT_ID = "massdriver.cloud/environment-id";
|
|
4
|
+
const ANNOTATION_INSTANCE_ID = "massdriver.cloud/instance-id";
|
|
5
|
+
|
|
6
|
+
export { ANNOTATION_ENVIRONMENT_ID, ANNOTATION_INSTANCE_ID, ANNOTATION_ORG_ID, ANNOTATION_PROJECT_ID };
|
|
7
|
+
//# sourceMappingURL=annotations.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.esm.js","sources":["../src/annotations.ts"],"sourcesContent":["/**\n * Catalog annotations that link a Backstage entity to a Massdriver resource.\n *\n * Frontend components render Massdriver UI only when the relevant annotation is\n * present on an entity. Add them to your own `catalog-info.yaml` to link an\n * entity to a Massdriver project, environment, or instance.\n *\n * @public\n */\nexport const ANNOTATION_ORG_ID = 'massdriver.cloud/org-id';\n\n/** @public */\nexport const ANNOTATION_PROJECT_ID = 'massdriver.cloud/project-id';\n\n/** @public */\nexport const ANNOTATION_ENVIRONMENT_ID = 'massdriver.cloud/environment-id';\n\n/** @public */\nexport const ANNOTATION_INSTANCE_ID = 'massdriver.cloud/instance-id';\n"],"names":[],"mappings":"AASO,MAAM,iBAAA,GAAoB;AAG1B,MAAM,qBAAA,GAAwB;AAG9B,MAAM,yBAAA,GAA4B;AAGlC,MAAM,sBAAA,GAAyB;;;;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var urls = require('./urls.cjs.js');
|
|
4
|
+
|
|
5
|
+
class MassdriverApiError extends Error {
|
|
6
|
+
constructor(message, status) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.name = "MassdriverApiError";
|
|
10
|
+
}
|
|
11
|
+
status;
|
|
12
|
+
}
|
|
13
|
+
const createMassdriverClient = (options) => {
|
|
14
|
+
const { token, organizationId, baseUrl = urls.DEFAULT_API_URL } = options;
|
|
15
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
16
|
+
const url = urls.graphqlUrl(baseUrl);
|
|
17
|
+
return {
|
|
18
|
+
organizationId,
|
|
19
|
+
async query(query, variables) {
|
|
20
|
+
const response = await doFetch(url, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
"content-type": "application/json",
|
|
24
|
+
authorization: `Bearer ${token}`
|
|
25
|
+
},
|
|
26
|
+
body: JSON.stringify({
|
|
27
|
+
query,
|
|
28
|
+
// Injected org id must win over caller-supplied variables.
|
|
29
|
+
variables: { ...variables, organizationId }
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new MassdriverApiError(
|
|
34
|
+
`Massdriver API request failed with status ${response.status}`,
|
|
35
|
+
response.status
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
const body = await response.json();
|
|
39
|
+
if (body.data !== void 0 && body.data !== null) {
|
|
40
|
+
return body.data;
|
|
41
|
+
}
|
|
42
|
+
if (body.errors?.length) {
|
|
43
|
+
throw new MassdriverApiError(
|
|
44
|
+
body.errors.map((error) => error.message).join("; ")
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (body.data === void 0) {
|
|
48
|
+
throw new MassdriverApiError("Massdriver API returned no data");
|
|
49
|
+
}
|
|
50
|
+
return body.data;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
exports.MassdriverApiError = MassdriverApiError;
|
|
56
|
+
exports.createMassdriverClient = createMassdriverClient;
|
|
57
|
+
//# sourceMappingURL=client.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.cjs.js","sources":["../src/client.ts"],"sourcesContent":["import { DEFAULT_API_URL, graphqlUrl } from './urls';\n\n/**\n * Options for {@link createMassdriverClient}.\n *\n * @public\n */\nexport interface MassdriverClientOptions {\n /** Service-account bearer token. Never leaves the backend. */\n token: string;\n /** Massdriver organization id; auto-injected into every query's variables. */\n organizationId: string;\n /** API origin. Defaults to {@link DEFAULT_API_URL}. */\n baseUrl?: string;\n /** Override the fetch implementation (defaults to the global `fetch`). */\n fetchImpl?: typeof fetch;\n}\n\n/** @public */\nexport interface MassdriverClient {\n organizationId: string;\n query<T = unknown>(\n query: string,\n variables?: Record<string, unknown>,\n ): Promise<T>;\n}\n\n/** @public */\nexport class MassdriverApiError extends Error {\n constructor(message: string, readonly status?: number) {\n super(message);\n this.name = 'MassdriverApiError';\n }\n}\n\n/**\n * Create a minimal, framework-agnostic client for the Massdriver v2 GraphQL API.\n *\n * Injects the `Authorization: Bearer` header and defaults `organizationId` into\n * every query's variables so operations only need to declare `$organizationId`.\n * Used server-side by the backend relay; the token must never be exposed to the\n * browser.\n *\n * @public\n */\nexport const createMassdriverClient = (\n options: MassdriverClientOptions,\n): MassdriverClient => {\n const { token, organizationId, baseUrl = DEFAULT_API_URL } = options;\n const doFetch = options.fetchImpl ?? fetch;\n const url = graphqlUrl(baseUrl);\n\n return {\n organizationId,\n async query<T = unknown>(\n query: string,\n variables?: Record<string, unknown>,\n ): Promise<T> {\n const response = await doFetch(url, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n authorization: `Bearer ${token}`,\n },\n body: JSON.stringify({\n query,\n // Injected org id must win over caller-supplied variables.\n variables: { ...variables, organizationId },\n }),\n });\n\n if (!response.ok) {\n throw new MassdriverApiError(\n `Massdriver API request failed with status ${response.status}`,\n response.status,\n );\n }\n\n const body = (await response.json()) as {\n data?: T;\n errors?: Array<{ message: string }>;\n };\n\n // When the query still returned data, hand it back even if there are\n // field-level errors (e.g. a NOT_FOUND on a nullable field like\n // `environment(id:)`). This lets callers render a 404 from a null field\n // instead of surfacing a 500. Only a total failure (no data) throws.\n if (body.data !== undefined && body.data !== null) {\n return body.data;\n }\n\n if (body.errors?.length) {\n throw new MassdriverApiError(\n body.errors.map(error => error.message).join('; '),\n );\n }\n\n if (body.data === undefined) {\n throw new MassdriverApiError('Massdriver API returned no data');\n }\n\n return body.data;\n },\n };\n};\n"],"names":["DEFAULT_API_URL","graphqlUrl"],"mappings":";;;;AA4BO,MAAM,2BAA2B,KAAA,CAAM;AAAA,EAC5C,WAAA,CAAY,SAA0B,MAAA,EAAiB;AACrD,IAAA,KAAA,CAAM,OAAO,CAAA;AADuB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAEpC,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AAAA,EACd;AAAA,EAHsC,MAAA;AAIxC;AAYO,MAAM,sBAAA,GAAyB,CACpC,OAAA,KACqB;AACrB,EAAA,MAAM,EAAE,KAAA,EAAO,cAAA,EAAgB,OAAA,GAAUA,sBAAgB,GAAI,OAAA;AAC7D,EAAA,MAAM,OAAA,GAAU,QAAQ,SAAA,IAAa,KAAA;AACrC,EAAA,MAAM,GAAA,GAAMC,gBAAW,OAAO,CAAA;AAE9B,EAAA,OAAO;AAAA,IACL,cAAA;AAAA,IACA,MAAM,KAAA,CACJ,KAAA,EACA,SAAA,EACY;AACZ,MAAA,MAAM,QAAA,GAAW,MAAM,OAAA,CAAQ,GAAA,EAAK;AAAA,QAClC,MAAA,EAAQ,MAAA;AAAA,QACR,OAAA,EAAS;AAAA,UACP,cAAA,EAAgB,kBAAA;AAAA,UAChB,aAAA,EAAe,UAAU,KAAK,CAAA;AAAA,SAChC;AAAA,QACA,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,UACnB,KAAA;AAAA;AAAA,UAEA,SAAA,EAAW,EAAE,GAAG,SAAA,EAAW,cAAA;AAAe,SAC3C;AAAA,OACF,CAAA;AAED,MAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,QAAA,MAAM,IAAI,kBAAA;AAAA,UACR,CAAA,0CAAA,EAA6C,SAAS,MAAM,CAAA,CAAA;AAAA,UAC5D,QAAA,CAAS;AAAA,SACX;AAAA,MACF;AAEA,MAAA,MAAM,IAAA,GAAQ,MAAM,QAAA,CAAS,IAAA,EAAK;AASlC,MAAA,IAAI,IAAA,CAAK,IAAA,KAAS,MAAA,IAAa,IAAA,CAAK,SAAS,IAAA,EAAM;AACjD,QAAA,OAAO,IAAA,CAAK,IAAA;AAAA,MACd;AAEA,MAAA,IAAI,IAAA,CAAK,QAAQ,MAAA,EAAQ;AACvB,QAAA,MAAM,IAAI,kBAAA;AAAA,UACR,IAAA,CAAK,OAAO,GAAA,CAAI,CAAA,KAAA,KAAS,MAAM,OAAO,CAAA,CAAE,KAAK,IAAI;AAAA,SACnD;AAAA,MACF;AAEA,MAAA,IAAI,IAAA,CAAK,SAAS,MAAA,EAAW;AAC3B,QAAA,MAAM,IAAI,mBAAmB,iCAAiC,CAAA;AAAA,MAChE;AAEA,MAAA,OAAO,IAAA,CAAK,IAAA;AAAA,IACd;AAAA,GACF;AACF;;;;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DEFAULT_API_URL, graphqlUrl } from './urls.esm.js';
|
|
2
|
+
|
|
3
|
+
class MassdriverApiError extends Error {
|
|
4
|
+
constructor(message, status) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.name = "MassdriverApiError";
|
|
8
|
+
}
|
|
9
|
+
status;
|
|
10
|
+
}
|
|
11
|
+
const createMassdriverClient = (options) => {
|
|
12
|
+
const { token, organizationId, baseUrl = DEFAULT_API_URL } = options;
|
|
13
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
14
|
+
const url = graphqlUrl(baseUrl);
|
|
15
|
+
return {
|
|
16
|
+
organizationId,
|
|
17
|
+
async query(query, variables) {
|
|
18
|
+
const response = await doFetch(url, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"content-type": "application/json",
|
|
22
|
+
authorization: `Bearer ${token}`
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
query,
|
|
26
|
+
// Injected org id must win over caller-supplied variables.
|
|
27
|
+
variables: { ...variables, organizationId }
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new MassdriverApiError(
|
|
32
|
+
`Massdriver API request failed with status ${response.status}`,
|
|
33
|
+
response.status
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
const body = await response.json();
|
|
37
|
+
if (body.data !== void 0 && body.data !== null) {
|
|
38
|
+
return body.data;
|
|
39
|
+
}
|
|
40
|
+
if (body.errors?.length) {
|
|
41
|
+
throw new MassdriverApiError(
|
|
42
|
+
body.errors.map((error) => error.message).join("; ")
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
if (body.data === void 0) {
|
|
46
|
+
throw new MassdriverApiError("Massdriver API returned no data");
|
|
47
|
+
}
|
|
48
|
+
return body.data;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { MassdriverApiError, createMassdriverClient };
|
|
54
|
+
//# sourceMappingURL=client.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.esm.js","sources":["../src/client.ts"],"sourcesContent":["import { DEFAULT_API_URL, graphqlUrl } from './urls';\n\n/**\n * Options for {@link createMassdriverClient}.\n *\n * @public\n */\nexport interface MassdriverClientOptions {\n /** Service-account bearer token. Never leaves the backend. */\n token: string;\n /** Massdriver organization id; auto-injected into every query's variables. */\n organizationId: string;\n /** API origin. Defaults to {@link DEFAULT_API_URL}. */\n baseUrl?: string;\n /** Override the fetch implementation (defaults to the global `fetch`). */\n fetchImpl?: typeof fetch;\n}\n\n/** @public */\nexport interface MassdriverClient {\n organizationId: string;\n query<T = unknown>(\n query: string,\n variables?: Record<string, unknown>,\n ): Promise<T>;\n}\n\n/** @public */\nexport class MassdriverApiError extends Error {\n constructor(message: string, readonly status?: number) {\n super(message);\n this.name = 'MassdriverApiError';\n }\n}\n\n/**\n * Create a minimal, framework-agnostic client for the Massdriver v2 GraphQL API.\n *\n * Injects the `Authorization: Bearer` header and defaults `organizationId` into\n * every query's variables so operations only need to declare `$organizationId`.\n * Used server-side by the backend relay; the token must never be exposed to the\n * browser.\n *\n * @public\n */\nexport const createMassdriverClient = (\n options: MassdriverClientOptions,\n): MassdriverClient => {\n const { token, organizationId, baseUrl = DEFAULT_API_URL } = options;\n const doFetch = options.fetchImpl ?? fetch;\n const url = graphqlUrl(baseUrl);\n\n return {\n organizationId,\n async query<T = unknown>(\n query: string,\n variables?: Record<string, unknown>,\n ): Promise<T> {\n const response = await doFetch(url, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n authorization: `Bearer ${token}`,\n },\n body: JSON.stringify({\n query,\n // Injected org id must win over caller-supplied variables.\n variables: { ...variables, organizationId },\n }),\n });\n\n if (!response.ok) {\n throw new MassdriverApiError(\n `Massdriver API request failed with status ${response.status}`,\n response.status,\n );\n }\n\n const body = (await response.json()) as {\n data?: T;\n errors?: Array<{ message: string }>;\n };\n\n // When the query still returned data, hand it back even if there are\n // field-level errors (e.g. a NOT_FOUND on a nullable field like\n // `environment(id:)`). This lets callers render a 404 from a null field\n // instead of surfacing a 500. Only a total failure (no data) throws.\n if (body.data !== undefined && body.data !== null) {\n return body.data;\n }\n\n if (body.errors?.length) {\n throw new MassdriverApiError(\n body.errors.map(error => error.message).join('; '),\n );\n }\n\n if (body.data === undefined) {\n throw new MassdriverApiError('Massdriver API returned no data');\n }\n\n return body.data;\n },\n };\n};\n"],"names":[],"mappings":";;AA4BO,MAAM,2BAA2B,KAAA,CAAM;AAAA,EAC5C,WAAA,CAAY,SAA0B,MAAA,EAAiB;AACrD,IAAA,KAAA,CAAM,OAAO,CAAA;AADuB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAEpC,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AAAA,EACd;AAAA,EAHsC,MAAA;AAIxC;AAYO,MAAM,sBAAA,GAAyB,CACpC,OAAA,KACqB;AACrB,EAAA,MAAM,EAAE,KAAA,EAAO,cAAA,EAAgB,OAAA,GAAU,iBAAgB,GAAI,OAAA;AAC7D,EAAA,MAAM,OAAA,GAAU,QAAQ,SAAA,IAAa,KAAA;AACrC,EAAA,MAAM,GAAA,GAAM,WAAW,OAAO,CAAA;AAE9B,EAAA,OAAO;AAAA,IACL,cAAA;AAAA,IACA,MAAM,KAAA,CACJ,KAAA,EACA,SAAA,EACY;AACZ,MAAA,MAAM,QAAA,GAAW,MAAM,OAAA,CAAQ,GAAA,EAAK;AAAA,QAClC,MAAA,EAAQ,MAAA;AAAA,QACR,OAAA,EAAS;AAAA,UACP,cAAA,EAAgB,kBAAA;AAAA,UAChB,aAAA,EAAe,UAAU,KAAK,CAAA;AAAA,SAChC;AAAA,QACA,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,UACnB,KAAA;AAAA;AAAA,UAEA,SAAA,EAAW,EAAE,GAAG,SAAA,EAAW,cAAA;AAAe,SAC3C;AAAA,OACF,CAAA;AAED,MAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,QAAA,MAAM,IAAI,kBAAA;AAAA,UACR,CAAA,0CAAA,EAA6C,SAAS,MAAM,CAAA,CAAA;AAAA,UAC5D,QAAA,CAAS;AAAA,SACX;AAAA,MACF;AAEA,MAAA,MAAM,IAAA,GAAQ,MAAM,QAAA,CAAS,IAAA,EAAK;AASlC,MAAA,IAAI,IAAA,CAAK,IAAA,KAAS,MAAA,IAAa,IAAA,CAAK,SAAS,IAAA,EAAM;AACjD,QAAA,OAAO,IAAA,CAAK,IAAA;AAAA,MACd;AAEA,MAAA,IAAI,IAAA,CAAK,QAAQ,MAAA,EAAQ;AACvB,QAAA,MAAM,IAAI,kBAAA;AAAA,UACR,IAAA,CAAK,OAAO,GAAA,CAAI,CAAA,KAAA,KAAS,MAAM,OAAO,CAAA,CAAE,KAAK,IAAI;AAAA,SACnD;AAAA,MACF;AAEA,MAAA,IAAI,IAAA,CAAK,SAAS,MAAA,EAAW;AAC3B,QAAA,MAAM,IAAI,mBAAmB,iCAAiC,CAAA;AAAA,MAChE;AAEA,MAAA,OAAO,IAAA,CAAK,IAAA;AAAA,IACd;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var urls = require('./urls.cjs.js');
|
|
4
|
+
|
|
5
|
+
const MASSDRIVER_CONFIG_KEY = "massdriver";
|
|
6
|
+
const readMassdriverPublicConfig = (config) => {
|
|
7
|
+
const massdriver = config.getConfig(MASSDRIVER_CONFIG_KEY);
|
|
8
|
+
return {
|
|
9
|
+
organizationId: massdriver.getString("organizationId"),
|
|
10
|
+
baseUrl: massdriver.getOptionalString("baseUrl") ?? urls.DEFAULT_API_URL,
|
|
11
|
+
appUrl: massdriver.getOptionalString("appUrl") ?? urls.DEFAULT_APP_URL
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const readMassdriverConfig = (config) => {
|
|
15
|
+
const massdriver = config.getConfig(MASSDRIVER_CONFIG_KEY);
|
|
16
|
+
return {
|
|
17
|
+
...readMassdriverPublicConfig(config),
|
|
18
|
+
apiToken: massdriver.getString("apiToken")
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.MASSDRIVER_CONFIG_KEY = MASSDRIVER_CONFIG_KEY;
|
|
23
|
+
exports.readMassdriverConfig = readMassdriverConfig;
|
|
24
|
+
exports.readMassdriverPublicConfig = readMassdriverPublicConfig;
|
|
25
|
+
//# sourceMappingURL=config.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.cjs.js","sources":["../src/config.ts"],"sourcesContent":["import { Config } from '@backstage/config';\nimport { DEFAULT_API_URL, DEFAULT_APP_URL } from './urls';\n\n/** Root config key for all Massdriver plugin settings. @public */\nexport const MASSDRIVER_CONFIG_KEY = 'massdriver';\n\n/**\n * Non-secret Massdriver settings, safe to read on the frontend.\n *\n * @public\n */\nexport interface MassdriverPublicConfig {\n organizationId: string;\n /** API origin for GraphQL. Defaults to {@link DEFAULT_API_URL}. */\n baseUrl: string;\n /** Web app origin for deep-links. Defaults to {@link DEFAULT_APP_URL}. */\n appUrl: string;\n}\n\n/**\n * Full Massdriver settings including the backend-only service-account token.\n *\n * @public\n */\nexport interface MassdriverConfig extends MassdriverPublicConfig {\n apiToken: string;\n}\n\n/**\n * Read the non-secret Massdriver settings. Safe on the frontend, where\n * `apiToken` is filtered out by config visibility.\n *\n * @public\n */\nexport const readMassdriverPublicConfig = (\n config: Config,\n): MassdriverPublicConfig => {\n const massdriver = config.getConfig(MASSDRIVER_CONFIG_KEY);\n return {\n organizationId: massdriver.getString('organizationId'),\n baseUrl: massdriver.getOptionalString('baseUrl') ?? DEFAULT_API_URL,\n appUrl: massdriver.getOptionalString('appUrl') ?? DEFAULT_APP_URL,\n };\n};\n\n/**\n * Read the full Massdriver settings, including the service-account token.\n * Backend-only — the token is never exposed to the frontend.\n *\n * @public\n */\nexport const readMassdriverConfig = (config: Config): MassdriverConfig => {\n const massdriver = config.getConfig(MASSDRIVER_CONFIG_KEY);\n return {\n ...readMassdriverPublicConfig(config),\n apiToken: massdriver.getString('apiToken'),\n };\n};\n"],"names":["DEFAULT_API_URL","DEFAULT_APP_URL"],"mappings":";;;;AAIO,MAAM,qBAAA,GAAwB;AA8B9B,MAAM,0BAAA,GAA6B,CACxC,MAAA,KAC2B;AAC3B,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,SAAA,CAAU,qBAAqB,CAAA;AACzD,EAAA,OAAO;AAAA,IACL,cAAA,EAAgB,UAAA,CAAW,SAAA,CAAU,gBAAgB,CAAA;AAAA,IACrD,OAAA,EAAS,UAAA,CAAW,iBAAA,CAAkB,SAAS,CAAA,IAAKA,oBAAA;AAAA,IACpD,MAAA,EAAQ,UAAA,CAAW,iBAAA,CAAkB,QAAQ,CAAA,IAAKC;AAAA,GACpD;AACF;AAQO,MAAM,oBAAA,GAAuB,CAAC,MAAA,KAAqC;AACxE,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,SAAA,CAAU,qBAAqB,CAAA;AACzD,EAAA,OAAO;AAAA,IACL,GAAG,2BAA2B,MAAM,CAAA;AAAA,IACpC,QAAA,EAAU,UAAA,CAAW,SAAA,CAAU,UAAU;AAAA,GAC3C;AACF;;;;;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DEFAULT_APP_URL, DEFAULT_API_URL } from './urls.esm.js';
|
|
2
|
+
|
|
3
|
+
const MASSDRIVER_CONFIG_KEY = "massdriver";
|
|
4
|
+
const readMassdriverPublicConfig = (config) => {
|
|
5
|
+
const massdriver = config.getConfig(MASSDRIVER_CONFIG_KEY);
|
|
6
|
+
return {
|
|
7
|
+
organizationId: massdriver.getString("organizationId"),
|
|
8
|
+
baseUrl: massdriver.getOptionalString("baseUrl") ?? DEFAULT_API_URL,
|
|
9
|
+
appUrl: massdriver.getOptionalString("appUrl") ?? DEFAULT_APP_URL
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const readMassdriverConfig = (config) => {
|
|
13
|
+
const massdriver = config.getConfig(MASSDRIVER_CONFIG_KEY);
|
|
14
|
+
return {
|
|
15
|
+
...readMassdriverPublicConfig(config),
|
|
16
|
+
apiToken: massdriver.getString("apiToken")
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { MASSDRIVER_CONFIG_KEY, readMassdriverConfig, readMassdriverPublicConfig };
|
|
21
|
+
//# sourceMappingURL=config.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.esm.js","sources":["../src/config.ts"],"sourcesContent":["import { Config } from '@backstage/config';\nimport { DEFAULT_API_URL, DEFAULT_APP_URL } from './urls';\n\n/** Root config key for all Massdriver plugin settings. @public */\nexport const MASSDRIVER_CONFIG_KEY = 'massdriver';\n\n/**\n * Non-secret Massdriver settings, safe to read on the frontend.\n *\n * @public\n */\nexport interface MassdriverPublicConfig {\n organizationId: string;\n /** API origin for GraphQL. Defaults to {@link DEFAULT_API_URL}. */\n baseUrl: string;\n /** Web app origin for deep-links. Defaults to {@link DEFAULT_APP_URL}. */\n appUrl: string;\n}\n\n/**\n * Full Massdriver settings including the backend-only service-account token.\n *\n * @public\n */\nexport interface MassdriverConfig extends MassdriverPublicConfig {\n apiToken: string;\n}\n\n/**\n * Read the non-secret Massdriver settings. Safe on the frontend, where\n * `apiToken` is filtered out by config visibility.\n *\n * @public\n */\nexport const readMassdriverPublicConfig = (\n config: Config,\n): MassdriverPublicConfig => {\n const massdriver = config.getConfig(MASSDRIVER_CONFIG_KEY);\n return {\n organizationId: massdriver.getString('organizationId'),\n baseUrl: massdriver.getOptionalString('baseUrl') ?? DEFAULT_API_URL,\n appUrl: massdriver.getOptionalString('appUrl') ?? DEFAULT_APP_URL,\n };\n};\n\n/**\n * Read the full Massdriver settings, including the service-account token.\n * Backend-only — the token is never exposed to the frontend.\n *\n * @public\n */\nexport const readMassdriverConfig = (config: Config): MassdriverConfig => {\n const massdriver = config.getConfig(MASSDRIVER_CONFIG_KEY);\n return {\n ...readMassdriverPublicConfig(config),\n apiToken: massdriver.getString('apiToken'),\n };\n};\n"],"names":[],"mappings":";;AAIO,MAAM,qBAAA,GAAwB;AA8B9B,MAAM,0BAAA,GAA6B,CACxC,MAAA,KAC2B;AAC3B,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,SAAA,CAAU,qBAAqB,CAAA;AACzD,EAAA,OAAO;AAAA,IACL,cAAA,EAAgB,UAAA,CAAW,SAAA,CAAU,gBAAgB,CAAA;AAAA,IACrD,OAAA,EAAS,UAAA,CAAW,iBAAA,CAAkB,SAAS,CAAA,IAAK,eAAA;AAAA,IACpD,MAAA,EAAQ,UAAA,CAAW,iBAAA,CAAkB,QAAQ,CAAA,IAAK;AAAA,GACpD;AACF;AAQO,MAAM,oBAAA,GAAuB,CAAC,MAAA,KAAqC;AACxE,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,SAAA,CAAU,qBAAqB,CAAA;AACzD,EAAA,OAAO;AAAA,IACL,GAAG,2BAA2B,MAAM,CAAA;AAAA,IACpC,QAAA,EAAU,UAAA,CAAW,SAAA,CAAU,UAAU;AAAA,GAC3C;AACF;;;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var annotations = require('./annotations.cjs.js');
|
|
4
|
+
var urls = require('./urls.cjs.js');
|
|
5
|
+
var client = require('./client.cjs.js');
|
|
6
|
+
var config = require('./config.cjs.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.ANNOTATION_ENVIRONMENT_ID = annotations.ANNOTATION_ENVIRONMENT_ID;
|
|
11
|
+
exports.ANNOTATION_INSTANCE_ID = annotations.ANNOTATION_INSTANCE_ID;
|
|
12
|
+
exports.ANNOTATION_ORG_ID = annotations.ANNOTATION_ORG_ID;
|
|
13
|
+
exports.ANNOTATION_PROJECT_ID = annotations.ANNOTATION_PROJECT_ID;
|
|
14
|
+
exports.DEFAULT_API_URL = urls.DEFAULT_API_URL;
|
|
15
|
+
exports.DEFAULT_APP_URL = urls.DEFAULT_APP_URL;
|
|
16
|
+
exports.GRAPHQL_PATH = urls.GRAPHQL_PATH;
|
|
17
|
+
exports.SOCKET_PATH = urls.SOCKET_PATH;
|
|
18
|
+
exports.composeEnvironmentId = urls.composeEnvironmentId;
|
|
19
|
+
exports.composeInstanceId = urls.composeInstanceId;
|
|
20
|
+
exports.environmentUrl = urls.environmentUrl;
|
|
21
|
+
exports.graphqlUrl = urls.graphqlUrl;
|
|
22
|
+
exports.instanceActionUrl = urls.instanceActionUrl;
|
|
23
|
+
exports.instanceTabUrl = urls.instanceTabUrl;
|
|
24
|
+
exports.instanceUrl = urls.instanceUrl;
|
|
25
|
+
exports.parseComponentId = urls.parseComponentId;
|
|
26
|
+
exports.parseEnvironmentId = urls.parseEnvironmentId;
|
|
27
|
+
exports.parseInstanceId = urls.parseInstanceId;
|
|
28
|
+
exports.projectUrl = urls.projectUrl;
|
|
29
|
+
exports.projectsUrl = urls.projectsUrl;
|
|
30
|
+
exports.repoTabUrl = urls.repoTabUrl;
|
|
31
|
+
exports.repoUrl = urls.repoUrl;
|
|
32
|
+
exports.repoVersionOverviewUrl = urls.repoVersionOverviewUrl;
|
|
33
|
+
exports.reposUrl = urls.reposUrl;
|
|
34
|
+
exports.resourceTabUrl = urls.resourceTabUrl;
|
|
35
|
+
exports.resourceUrl = urls.resourceUrl;
|
|
36
|
+
exports.resourcesUrl = urls.resourcesUrl;
|
|
37
|
+
exports.socketUrl = urls.socketUrl;
|
|
38
|
+
exports.MassdriverApiError = client.MassdriverApiError;
|
|
39
|
+
exports.createMassdriverClient = client.createMassdriverClient;
|
|
40
|
+
exports.MASSDRIVER_CONFIG_KEY = config.MASSDRIVER_CONFIG_KEY;
|
|
41
|
+
exports.readMassdriverConfig = config.readMassdriverConfig;
|
|
42
|
+
exports.readMassdriverPublicConfig = config.readMassdriverPublicConfig;
|
|
43
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { Config } from '@backstage/config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Catalog annotations that link a Backstage entity to a Massdriver resource.
|
|
5
|
+
*
|
|
6
|
+
* Frontend components render Massdriver UI only when the relevant annotation is
|
|
7
|
+
* present on an entity. Add them to your own `catalog-info.yaml` to link an
|
|
8
|
+
* entity to a Massdriver project, environment, or instance.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
declare const ANNOTATION_ORG_ID = "massdriver.cloud/org-id";
|
|
13
|
+
/** @public */
|
|
14
|
+
declare const ANNOTATION_PROJECT_ID = "massdriver.cloud/project-id";
|
|
15
|
+
/** @public */
|
|
16
|
+
declare const ANNOTATION_ENVIRONMENT_ID = "massdriver.cloud/environment-id";
|
|
17
|
+
/** @public */
|
|
18
|
+
declare const ANNOTATION_INSTANCE_ID = "massdriver.cloud/instance-id";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Default Massdriver SaaS origins. Overridable (e.g. for self-hosted instances)
|
|
22
|
+
* via the `massdriver.baseUrl` / `massdriver.appUrl` config keys.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
declare const DEFAULT_API_URL = "https://api.massdriver.cloud";
|
|
27
|
+
/** @public */
|
|
28
|
+
declare const DEFAULT_APP_URL = "https://app.massdriver.cloud";
|
|
29
|
+
/**
|
|
30
|
+
* Path of the v2 GraphQL endpoint on the API origin.
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
declare const GRAPHQL_PATH = "/api/v2/graphql";
|
|
35
|
+
/**
|
|
36
|
+
* Phoenix/Absinthe socket endpoint for a given API origin, mirroring the web
|
|
37
|
+
* app's `socketLink` (which connects to `${WS_URL}/api/socket`). The API origin
|
|
38
|
+
* uses `https`/`http`; the socket swaps it to `wss`/`ws`. Backend-only — the
|
|
39
|
+
* service-account token is appended as a query param server-side (the browser
|
|
40
|
+
* never opens this socket; it consumes the backend SSE relay instead).
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
declare const SOCKET_PATH = "/api/socket";
|
|
45
|
+
/** @public */
|
|
46
|
+
declare const socketUrl: (baseUrl?: string) => string;
|
|
47
|
+
/**
|
|
48
|
+
* Massdriver composite IDs join hyphen-free segments with `-`:
|
|
49
|
+
* - environment id: `{projectId}-{scopedEnvironmentId}`
|
|
50
|
+
* - instance id: `{projectId}-{scopedEnvironmentId}-{scopedComponentId}`
|
|
51
|
+
*
|
|
52
|
+
* The web app's URLs are keyed by the scoped segments, so deep-links are built
|
|
53
|
+
* by splitting the composite id. Mirrors `apps/web/shared/utils/ids.js`.
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
declare const parseEnvironmentId: (environmentId: string) => {
|
|
58
|
+
projectId: string;
|
|
59
|
+
scopedEnvironmentId: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Compose a full environment id from its parts: `{projectId}-{scopedEnvironmentId}`.
|
|
63
|
+
*
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
declare const composeEnvironmentId: (projectId: string, scopedEnvironmentId: string) => string;
|
|
67
|
+
/** @public */
|
|
68
|
+
declare const parseInstanceId: (instanceId: string) => {
|
|
69
|
+
projectId: string;
|
|
70
|
+
scopedEnvironmentId: string;
|
|
71
|
+
scopedComponentId: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Component ids are project-scoped: `{projectId}-{scopedComponentId}`. Mirrors
|
|
75
|
+
* `apps/web/shared/utils/ids.js` `parseComponentId`.
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
declare const parseComponentId: (componentId: string) => {
|
|
80
|
+
projectId: string;
|
|
81
|
+
scopedComponentId: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Compose a full instance id from its parts:
|
|
85
|
+
* `{projectId}-{scopedEnvironmentId}-{scopedComponentId}`. Mirrors
|
|
86
|
+
* `apps/web/shared/utils/ids.js` `composeInstanceId`.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
declare const composeInstanceId: (projectId: string, scopedEnvironmentId: string, scopedComponentId: string) => string;
|
|
91
|
+
/**
|
|
92
|
+
* Full URL of the v2 GraphQL endpoint for a given API origin.
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
declare const graphqlUrl: (baseUrl?: string) => string;
|
|
97
|
+
/**
|
|
98
|
+
* Deep-link into the Massdriver web app's projects list.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
declare const projectsUrl: (appUrl: string, orgId: string) => string;
|
|
103
|
+
/**
|
|
104
|
+
* Deep-link into the Massdriver web app for a project.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
declare const projectUrl: (appUrl: string, orgId: string, projectId: string) => string;
|
|
109
|
+
/**
|
|
110
|
+
* Deep-link into the Massdriver web app for an environment (its graph view).
|
|
111
|
+
*
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
declare const environmentUrl: (appUrl: string, orgId: string, environmentId: string) => string;
|
|
115
|
+
/**
|
|
116
|
+
* Deep-link into the Massdriver web app for a deployed instance's detail panel.
|
|
117
|
+
*
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
declare const instanceUrl: (appUrl: string, orgId: string, instanceId: string) => string;
|
|
121
|
+
/**
|
|
122
|
+
* Deep-link to a specific tab of an instance's detail panel in the web app,
|
|
123
|
+
* e.g. `?tab=overview` (change version) or `?tab=secrets` (set/clear secret).
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
declare const instanceTabUrl: (appUrl: string, orgId: string, instanceId: string, tab: string) => string;
|
|
128
|
+
/**
|
|
129
|
+
* Deep-link that opens one of the instance panel's action dialogs in the web
|
|
130
|
+
* app (`?action=copy | decommission | delete`), mirroring the app's
|
|
131
|
+
* `useDialogParam('action')`.
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
declare const instanceActionUrl: (appUrl: string, orgId: string, instanceId: string, action: "copy" | "decommission" | "delete") => string;
|
|
136
|
+
/**
|
|
137
|
+
* Deep-link into the Massdriver web app's repositories list.
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
declare const reposUrl: (appUrl: string, orgId: string) => string;
|
|
142
|
+
/**
|
|
143
|
+
* Deep-link to a repository's default view in the web app:
|
|
144
|
+
* `/orgs/{orgId}/repos/{repoId}/all` (the "all versions" view, matching the
|
|
145
|
+
* app's repo list link target).
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
declare const repoUrl: (appUrl: string, orgId: string, repoId: string) => string;
|
|
150
|
+
/**
|
|
151
|
+
* Deep-link to a specific tab of a repository version in the web app:
|
|
152
|
+
* `/orgs/{orgId}/repos/{repoId}/{version}/{tab}`. Version is `all` for the
|
|
153
|
+
* all-versions view.
|
|
154
|
+
*
|
|
155
|
+
* @public
|
|
156
|
+
*/
|
|
157
|
+
declare const repoTabUrl: (appUrl: string, orgId: string, repoId: string, version: string, tab: string) => string;
|
|
158
|
+
/**
|
|
159
|
+
* Deep-link into the Massdriver web app's resources list.
|
|
160
|
+
*
|
|
161
|
+
* @public
|
|
162
|
+
*/
|
|
163
|
+
declare const resourcesUrl: (appUrl: string, orgId: string) => string;
|
|
164
|
+
/**
|
|
165
|
+
* Deep-link to a specific tab of a resource's detail page in the web app:
|
|
166
|
+
* `/orgs/{orgId}/resources/{resourceId}/{tab}`.
|
|
167
|
+
*
|
|
168
|
+
* @public
|
|
169
|
+
*/
|
|
170
|
+
declare const resourceTabUrl: (appUrl: string, orgId: string, resourceId: string, tab: string) => string;
|
|
171
|
+
/**
|
|
172
|
+
* Deep-link to a cloud resource's detail page in the web app:
|
|
173
|
+
* `/orgs/{orgId}/resources/{resourceId}/general`. Used by the instance
|
|
174
|
+
* Dependencies/Resources tabs' "fulfilled by" / resource-name links.
|
|
175
|
+
*
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
declare const resourceUrl: (appUrl: string, orgId: string, resourceId: string) => string;
|
|
179
|
+
/**
|
|
180
|
+
* Deep-link to a bundle/OCI-repo version's overview in the web app:
|
|
181
|
+
* `/orgs/{orgId}/repos/{repoName}/{version}/overview`. Used by the instance
|
|
182
|
+
* Overview tab's "view in repository" link.
|
|
183
|
+
*
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
declare const repoVersionOverviewUrl: (appUrl: string, orgId: string, repoName: string, version: string) => string;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Lifecycle status of a Massdriver instance (deployed component).
|
|
190
|
+
*
|
|
191
|
+
* @public
|
|
192
|
+
*/
|
|
193
|
+
type InstanceStatus = 'INITIALIZED' | 'PROVISIONED' | 'DECOMMISSIONED' | 'FAILED';
|
|
194
|
+
/**
|
|
195
|
+
* Status of a Massdriver deployment.
|
|
196
|
+
*
|
|
197
|
+
* @public
|
|
198
|
+
*/
|
|
199
|
+
type DeploymentStatus = 'PROPOSED' | 'REJECTED' | 'APPROVED' | 'PENDING' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'ABORTED';
|
|
200
|
+
/**
|
|
201
|
+
* A Massdriver project, as fetched for catalog sync and read-only views.
|
|
202
|
+
*
|
|
203
|
+
* @public
|
|
204
|
+
*/
|
|
205
|
+
interface MassdriverProject {
|
|
206
|
+
id: string;
|
|
207
|
+
name: string;
|
|
208
|
+
description?: string | null;
|
|
209
|
+
}
|
|
210
|
+
/** @public */
|
|
211
|
+
interface MassdriverEnvironment {
|
|
212
|
+
id: string;
|
|
213
|
+
name: string;
|
|
214
|
+
description?: string | null;
|
|
215
|
+
project?: {
|
|
216
|
+
id: string;
|
|
217
|
+
} | null;
|
|
218
|
+
}
|
|
219
|
+
/** @public */
|
|
220
|
+
interface MassdriverInstance {
|
|
221
|
+
id: string;
|
|
222
|
+
name: string;
|
|
223
|
+
status: InstanceStatus;
|
|
224
|
+
resolvedVersion?: string | null;
|
|
225
|
+
deployedVersion?: string | null;
|
|
226
|
+
environment?: {
|
|
227
|
+
id: string;
|
|
228
|
+
} | null;
|
|
229
|
+
}
|
|
230
|
+
/** @public */
|
|
231
|
+
interface MassdriverDeployment {
|
|
232
|
+
id: string;
|
|
233
|
+
status: DeploymentStatus;
|
|
234
|
+
action?: string | null;
|
|
235
|
+
version?: string | null;
|
|
236
|
+
deployedBy?: string | null;
|
|
237
|
+
instance?: {
|
|
238
|
+
id: string;
|
|
239
|
+
} | null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Options for {@link createMassdriverClient}.
|
|
244
|
+
*
|
|
245
|
+
* @public
|
|
246
|
+
*/
|
|
247
|
+
interface MassdriverClientOptions {
|
|
248
|
+
/** Service-account bearer token. Never leaves the backend. */
|
|
249
|
+
token: string;
|
|
250
|
+
/** Massdriver organization id; auto-injected into every query's variables. */
|
|
251
|
+
organizationId: string;
|
|
252
|
+
/** API origin. Defaults to {@link DEFAULT_API_URL}. */
|
|
253
|
+
baseUrl?: string;
|
|
254
|
+
/** Override the fetch implementation (defaults to the global `fetch`). */
|
|
255
|
+
fetchImpl?: typeof fetch;
|
|
256
|
+
}
|
|
257
|
+
/** @public */
|
|
258
|
+
interface MassdriverClient {
|
|
259
|
+
organizationId: string;
|
|
260
|
+
query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
|
|
261
|
+
}
|
|
262
|
+
/** @public */
|
|
263
|
+
declare class MassdriverApiError extends Error {
|
|
264
|
+
readonly status?: number | undefined;
|
|
265
|
+
constructor(message: string, status?: number | undefined);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Create a minimal, framework-agnostic client for the Massdriver v2 GraphQL API.
|
|
269
|
+
*
|
|
270
|
+
* Injects the `Authorization: Bearer` header and defaults `organizationId` into
|
|
271
|
+
* every query's variables so operations only need to declare `$organizationId`.
|
|
272
|
+
* Used server-side by the backend relay; the token must never be exposed to the
|
|
273
|
+
* browser.
|
|
274
|
+
*
|
|
275
|
+
* @public
|
|
276
|
+
*/
|
|
277
|
+
declare const createMassdriverClient: (options: MassdriverClientOptions) => MassdriverClient;
|
|
278
|
+
|
|
279
|
+
/** Root config key for all Massdriver plugin settings. @public */
|
|
280
|
+
declare const MASSDRIVER_CONFIG_KEY = "massdriver";
|
|
281
|
+
/**
|
|
282
|
+
* Non-secret Massdriver settings, safe to read on the frontend.
|
|
283
|
+
*
|
|
284
|
+
* @public
|
|
285
|
+
*/
|
|
286
|
+
interface MassdriverPublicConfig {
|
|
287
|
+
organizationId: string;
|
|
288
|
+
/** API origin for GraphQL. Defaults to {@link DEFAULT_API_URL}. */
|
|
289
|
+
baseUrl: string;
|
|
290
|
+
/** Web app origin for deep-links. Defaults to {@link DEFAULT_APP_URL}. */
|
|
291
|
+
appUrl: string;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Full Massdriver settings including the backend-only service-account token.
|
|
295
|
+
*
|
|
296
|
+
* @public
|
|
297
|
+
*/
|
|
298
|
+
interface MassdriverConfig extends MassdriverPublicConfig {
|
|
299
|
+
apiToken: string;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Read the non-secret Massdriver settings. Safe on the frontend, where
|
|
303
|
+
* `apiToken` is filtered out by config visibility.
|
|
304
|
+
*
|
|
305
|
+
* @public
|
|
306
|
+
*/
|
|
307
|
+
declare const readMassdriverPublicConfig: (config: Config) => MassdriverPublicConfig;
|
|
308
|
+
/**
|
|
309
|
+
* Read the full Massdriver settings, including the service-account token.
|
|
310
|
+
* Backend-only — the token is never exposed to the frontend.
|
|
311
|
+
*
|
|
312
|
+
* @public
|
|
313
|
+
*/
|
|
314
|
+
declare const readMassdriverConfig: (config: Config) => MassdriverConfig;
|
|
315
|
+
|
|
316
|
+
export { ANNOTATION_ENVIRONMENT_ID, ANNOTATION_INSTANCE_ID, ANNOTATION_ORG_ID, ANNOTATION_PROJECT_ID, DEFAULT_API_URL, DEFAULT_APP_URL, GRAPHQL_PATH, MASSDRIVER_CONFIG_KEY, MassdriverApiError, SOCKET_PATH, composeEnvironmentId, composeInstanceId, createMassdriverClient, environmentUrl, graphqlUrl, instanceActionUrl, instanceTabUrl, instanceUrl, parseComponentId, parseEnvironmentId, parseInstanceId, projectUrl, projectsUrl, readMassdriverConfig, readMassdriverPublicConfig, repoTabUrl, repoUrl, repoVersionOverviewUrl, reposUrl, resourceTabUrl, resourceUrl, resourcesUrl, socketUrl };
|
|
317
|
+
export type { DeploymentStatus, InstanceStatus, MassdriverClient, MassdriverClientOptions, MassdriverConfig, MassdriverDeployment, MassdriverEnvironment, MassdriverInstance, MassdriverProject, MassdriverPublicConfig };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ANNOTATION_ENVIRONMENT_ID, ANNOTATION_INSTANCE_ID, ANNOTATION_ORG_ID, ANNOTATION_PROJECT_ID } from './annotations.esm.js';
|
|
2
|
+
export { DEFAULT_API_URL, DEFAULT_APP_URL, GRAPHQL_PATH, SOCKET_PATH, composeEnvironmentId, composeInstanceId, environmentUrl, graphqlUrl, instanceActionUrl, instanceTabUrl, instanceUrl, parseComponentId, parseEnvironmentId, parseInstanceId, projectUrl, projectsUrl, repoTabUrl, repoUrl, repoVersionOverviewUrl, reposUrl, resourceTabUrl, resourceUrl, resourcesUrl, socketUrl } from './urls.esm.js';
|
|
3
|
+
export { MassdriverApiError, createMassdriverClient } from './client.esm.js';
|
|
4
|
+
export { MASSDRIVER_CONFIG_KEY, readMassdriverConfig, readMassdriverPublicConfig } from './config.esm.js';
|
|
5
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
package/dist/urls.cjs.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_API_URL = "https://api.massdriver.cloud";
|
|
4
|
+
const DEFAULT_APP_URL = "https://app.massdriver.cloud";
|
|
5
|
+
const GRAPHQL_PATH = "/api/v2/graphql";
|
|
6
|
+
const trimTrailingSlash = (url) => url.replace(/\/+$/, "");
|
|
7
|
+
const SOCKET_PATH = "/api/socket";
|
|
8
|
+
const socketUrl = (baseUrl = DEFAULT_API_URL) => {
|
|
9
|
+
const swapped = trimTrailingSlash(baseUrl).replace(
|
|
10
|
+
/^http(s?):\/\//,
|
|
11
|
+
"ws$1://"
|
|
12
|
+
);
|
|
13
|
+
return `${swapped}${SOCKET_PATH}`;
|
|
14
|
+
};
|
|
15
|
+
const parseEnvironmentId = (environmentId) => {
|
|
16
|
+
const [projectId, scopedEnvironmentId] = environmentId.split("-");
|
|
17
|
+
return { projectId, scopedEnvironmentId };
|
|
18
|
+
};
|
|
19
|
+
const composeEnvironmentId = (projectId, scopedEnvironmentId) => `${projectId}-${scopedEnvironmentId}`;
|
|
20
|
+
const parseInstanceId = (instanceId) => {
|
|
21
|
+
const [projectId, scopedEnvironmentId, scopedComponentId] = instanceId.split("-");
|
|
22
|
+
return { projectId, scopedEnvironmentId, scopedComponentId };
|
|
23
|
+
};
|
|
24
|
+
const parseComponentId = (componentId) => {
|
|
25
|
+
const [projectId, scopedComponentId] = componentId.split("-");
|
|
26
|
+
return { projectId, scopedComponentId };
|
|
27
|
+
};
|
|
28
|
+
const composeInstanceId = (projectId, scopedEnvironmentId, scopedComponentId) => `${projectId}-${scopedEnvironmentId}-${scopedComponentId}`;
|
|
29
|
+
const graphqlUrl = (baseUrl = DEFAULT_API_URL) => `${trimTrailingSlash(baseUrl)}${GRAPHQL_PATH}`;
|
|
30
|
+
const projectsUrl = (appUrl, orgId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/projects`;
|
|
31
|
+
const projectUrl = (appUrl, orgId, projectId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/projects/${projectId}`;
|
|
32
|
+
const environmentUrl = (appUrl, orgId, environmentId) => {
|
|
33
|
+
const { projectId, scopedEnvironmentId } = parseEnvironmentId(environmentId);
|
|
34
|
+
return `${projectUrl(
|
|
35
|
+
appUrl,
|
|
36
|
+
orgId,
|
|
37
|
+
projectId
|
|
38
|
+
)}/environments/${scopedEnvironmentId}`;
|
|
39
|
+
};
|
|
40
|
+
const instanceUrl = (appUrl, orgId, instanceId) => {
|
|
41
|
+
const { projectId, scopedEnvironmentId, scopedComponentId } = parseInstanceId(instanceId);
|
|
42
|
+
return `${trimTrailingSlash(
|
|
43
|
+
appUrl
|
|
44
|
+
)}/orgs/${orgId}/projects/${projectId}/environments/${scopedEnvironmentId}/instances/${scopedComponentId}`;
|
|
45
|
+
};
|
|
46
|
+
const instanceTabUrl = (appUrl, orgId, instanceId, tab) => `${instanceUrl(appUrl, orgId, instanceId)}?tab=${tab}`;
|
|
47
|
+
const instanceActionUrl = (appUrl, orgId, instanceId, action) => `${instanceUrl(appUrl, orgId, instanceId)}?action=${action}`;
|
|
48
|
+
const reposUrl = (appUrl, orgId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos`;
|
|
49
|
+
const repoUrl = (appUrl, orgId, repoId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos/${encodeURIComponent(
|
|
50
|
+
repoId
|
|
51
|
+
)}/all`;
|
|
52
|
+
const repoTabUrl = (appUrl, orgId, repoId, version, tab) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos/${encodeURIComponent(
|
|
53
|
+
repoId
|
|
54
|
+
)}/${encodeURIComponent(version)}/${tab}`;
|
|
55
|
+
const resourcesUrl = (appUrl, orgId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources`;
|
|
56
|
+
const resourceTabUrl = (appUrl, orgId, resourceId, tab) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources/${encodeURIComponent(
|
|
57
|
+
resourceId
|
|
58
|
+
)}/${tab}`;
|
|
59
|
+
const resourceUrl = (appUrl, orgId, resourceId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources/${encodeURIComponent(
|
|
60
|
+
resourceId
|
|
61
|
+
)}/general`;
|
|
62
|
+
const repoVersionOverviewUrl = (appUrl, orgId, repoName, version) => `${trimTrailingSlash(
|
|
63
|
+
appUrl
|
|
64
|
+
)}/orgs/${orgId}/repos/${repoName}/${version}/overview`;
|
|
65
|
+
|
|
66
|
+
exports.DEFAULT_API_URL = DEFAULT_API_URL;
|
|
67
|
+
exports.DEFAULT_APP_URL = DEFAULT_APP_URL;
|
|
68
|
+
exports.GRAPHQL_PATH = GRAPHQL_PATH;
|
|
69
|
+
exports.SOCKET_PATH = SOCKET_PATH;
|
|
70
|
+
exports.composeEnvironmentId = composeEnvironmentId;
|
|
71
|
+
exports.composeInstanceId = composeInstanceId;
|
|
72
|
+
exports.environmentUrl = environmentUrl;
|
|
73
|
+
exports.graphqlUrl = graphqlUrl;
|
|
74
|
+
exports.instanceActionUrl = instanceActionUrl;
|
|
75
|
+
exports.instanceTabUrl = instanceTabUrl;
|
|
76
|
+
exports.instanceUrl = instanceUrl;
|
|
77
|
+
exports.parseComponentId = parseComponentId;
|
|
78
|
+
exports.parseEnvironmentId = parseEnvironmentId;
|
|
79
|
+
exports.parseInstanceId = parseInstanceId;
|
|
80
|
+
exports.projectUrl = projectUrl;
|
|
81
|
+
exports.projectsUrl = projectsUrl;
|
|
82
|
+
exports.repoTabUrl = repoTabUrl;
|
|
83
|
+
exports.repoUrl = repoUrl;
|
|
84
|
+
exports.repoVersionOverviewUrl = repoVersionOverviewUrl;
|
|
85
|
+
exports.reposUrl = reposUrl;
|
|
86
|
+
exports.resourceTabUrl = resourceTabUrl;
|
|
87
|
+
exports.resourceUrl = resourceUrl;
|
|
88
|
+
exports.resourcesUrl = resourcesUrl;
|
|
89
|
+
exports.socketUrl = socketUrl;
|
|
90
|
+
//# sourceMappingURL=urls.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urls.cjs.js","sources":["../src/urls.ts"],"sourcesContent":["/**\n * Default Massdriver SaaS origins. Overridable (e.g. for self-hosted instances)\n * via the `massdriver.baseUrl` / `massdriver.appUrl` config keys.\n *\n * @public\n */\nexport const DEFAULT_API_URL = 'https://api.massdriver.cloud';\n\n/** @public */\nexport const DEFAULT_APP_URL = 'https://app.massdriver.cloud';\n\n/**\n * Path of the v2 GraphQL endpoint on the API origin.\n *\n * @public\n */\nexport const GRAPHQL_PATH = '/api/v2/graphql';\n\nconst trimTrailingSlash = (url: string): string => url.replace(/\\/+$/, '');\n\n/**\n * Phoenix/Absinthe socket endpoint for a given API origin, mirroring the web\n * app's `socketLink` (which connects to `${WS_URL}/api/socket`). The API origin\n * uses `https`/`http`; the socket swaps it to `wss`/`ws`. Backend-only — the\n * service-account token is appended as a query param server-side (the browser\n * never opens this socket; it consumes the backend SSE relay instead).\n *\n * @public\n */\nexport const SOCKET_PATH = '/api/socket';\n\n/** @public */\nexport const socketUrl = (baseUrl: string = DEFAULT_API_URL): string => {\n const swapped = trimTrailingSlash(baseUrl).replace(\n /^http(s?):\\/\\//,\n 'ws$1://',\n );\n return `${swapped}${SOCKET_PATH}`;\n};\n\n/**\n * Massdriver composite IDs join hyphen-free segments with `-`:\n * - environment id: `{projectId}-{scopedEnvironmentId}`\n * - instance id: `{projectId}-{scopedEnvironmentId}-{scopedComponentId}`\n *\n * The web app's URLs are keyed by the scoped segments, so deep-links are built\n * by splitting the composite id. Mirrors `apps/web/shared/utils/ids.js`.\n *\n * @public\n */\nexport const parseEnvironmentId = (\n environmentId: string,\n): { projectId: string; scopedEnvironmentId: string } => {\n const [projectId, scopedEnvironmentId] = environmentId.split('-');\n return { projectId, scopedEnvironmentId };\n};\n\n/**\n * Compose a full environment id from its parts: `{projectId}-{scopedEnvironmentId}`.\n *\n * @public\n */\nexport const composeEnvironmentId = (\n projectId: string,\n scopedEnvironmentId: string,\n): string => `${projectId}-${scopedEnvironmentId}`;\n\n/** @public */\nexport const parseInstanceId = (\n instanceId: string,\n): {\n projectId: string;\n scopedEnvironmentId: string;\n scopedComponentId: string;\n} => {\n const [projectId, scopedEnvironmentId, scopedComponentId] =\n instanceId.split('-');\n return { projectId, scopedEnvironmentId, scopedComponentId };\n};\n\n/**\n * Component ids are project-scoped: `{projectId}-{scopedComponentId}`. Mirrors\n * `apps/web/shared/utils/ids.js` `parseComponentId`.\n *\n * @public\n */\nexport const parseComponentId = (\n componentId: string,\n): { projectId: string; scopedComponentId: string } => {\n const [projectId, scopedComponentId] = componentId.split('-');\n return { projectId, scopedComponentId };\n};\n\n/**\n * Compose a full instance id from its parts:\n * `{projectId}-{scopedEnvironmentId}-{scopedComponentId}`. Mirrors\n * `apps/web/shared/utils/ids.js` `composeInstanceId`.\n *\n * @public\n */\nexport const composeInstanceId = (\n projectId: string,\n scopedEnvironmentId: string,\n scopedComponentId: string,\n): string => `${projectId}-${scopedEnvironmentId}-${scopedComponentId}`;\n\n/**\n * Full URL of the v2 GraphQL endpoint for a given API origin.\n *\n * @public\n */\nexport const graphqlUrl = (baseUrl: string = DEFAULT_API_URL): string =>\n `${trimTrailingSlash(baseUrl)}${GRAPHQL_PATH}`;\n\n/**\n * Deep-link into the Massdriver web app's projects list.\n *\n * @public\n */\nexport const projectsUrl = (appUrl: string, orgId: string): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/projects`;\n\n/**\n * Deep-link into the Massdriver web app for a project.\n *\n * @public\n */\nexport const projectUrl = (\n appUrl: string,\n orgId: string,\n projectId: string,\n): string => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/projects/${projectId}`;\n\n/**\n * Deep-link into the Massdriver web app for an environment (its graph view).\n *\n * @public\n */\nexport const environmentUrl = (\n appUrl: string,\n orgId: string,\n environmentId: string,\n): string => {\n const { projectId, scopedEnvironmentId } = parseEnvironmentId(environmentId);\n return `${projectUrl(\n appUrl,\n orgId,\n projectId,\n )}/environments/${scopedEnvironmentId}`;\n};\n\n/**\n * Deep-link into the Massdriver web app for a deployed instance's detail panel.\n *\n * @public\n */\nexport const instanceUrl = (\n appUrl: string,\n orgId: string,\n instanceId: string,\n): string => {\n const { projectId, scopedEnvironmentId, scopedComponentId } =\n parseInstanceId(instanceId);\n return `${trimTrailingSlash(\n appUrl,\n )}/orgs/${orgId}/projects/${projectId}/environments/${scopedEnvironmentId}/instances/${scopedComponentId}`;\n};\n\n/**\n * Deep-link to a specific tab of an instance's detail panel in the web app,\n * e.g. `?tab=overview` (change version) or `?tab=secrets` (set/clear secret).\n *\n * @public\n */\nexport const instanceTabUrl = (\n appUrl: string,\n orgId: string,\n instanceId: string,\n tab: string,\n): string => `${instanceUrl(appUrl, orgId, instanceId)}?tab=${tab}`;\n\n/**\n * Deep-link that opens one of the instance panel's action dialogs in the web\n * app (`?action=copy | decommission | delete`), mirroring the app's\n * `useDialogParam('action')`.\n *\n * @public\n */\nexport const instanceActionUrl = (\n appUrl: string,\n orgId: string,\n instanceId: string,\n action: 'copy' | 'decommission' | 'delete',\n): string => `${instanceUrl(appUrl, orgId, instanceId)}?action=${action}`;\n\n/**\n * Deep-link into the Massdriver web app's repositories list.\n *\n * @public\n */\nexport const reposUrl = (appUrl: string, orgId: string): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos`;\n\n/**\n * Deep-link to a repository's default view in the web app:\n * `/orgs/{orgId}/repos/{repoId}/all` (the \"all versions\" view, matching the\n * app's repo list link target).\n *\n * @public\n */\nexport const repoUrl = (\n appUrl: string,\n orgId: string,\n repoId: string,\n): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos/${encodeURIComponent(\n repoId,\n )}/all`;\n\n/**\n * Deep-link to a specific tab of a repository version in the web app:\n * `/orgs/{orgId}/repos/{repoId}/{version}/{tab}`. Version is `all` for the\n * all-versions view.\n *\n * @public\n */\nexport const repoTabUrl = (\n appUrl: string,\n orgId: string,\n repoId: string,\n version: string,\n tab: string,\n): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos/${encodeURIComponent(\n repoId,\n )}/${encodeURIComponent(version)}/${tab}`;\n\n/**\n * Deep-link into the Massdriver web app's resources list.\n *\n * @public\n */\nexport const resourcesUrl = (appUrl: string, orgId: string): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources`;\n\n/**\n * Deep-link to a specific tab of a resource's detail page in the web app:\n * `/orgs/{orgId}/resources/{resourceId}/{tab}`.\n *\n * @public\n */\nexport const resourceTabUrl = (\n appUrl: string,\n orgId: string,\n resourceId: string,\n tab: string,\n): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources/${encodeURIComponent(\n resourceId,\n )}/${tab}`;\n\n/**\n * Deep-link to a cloud resource's detail page in the web app:\n * `/orgs/{orgId}/resources/{resourceId}/general`. Used by the instance\n * Dependencies/Resources tabs' \"fulfilled by\" / resource-name links.\n *\n * @public\n */\nexport const resourceUrl = (\n appUrl: string,\n orgId: string,\n resourceId: string,\n): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources/${encodeURIComponent(\n resourceId,\n )}/general`;\n\n/**\n * Deep-link to a bundle/OCI-repo version's overview in the web app:\n * `/orgs/{orgId}/repos/{repoName}/{version}/overview`. Used by the instance\n * Overview tab's \"view in repository\" link.\n *\n * @public\n */\nexport const repoVersionOverviewUrl = (\n appUrl: string,\n orgId: string,\n repoName: string,\n version: string,\n): string =>\n `${trimTrailingSlash(\n appUrl,\n )}/orgs/${orgId}/repos/${repoName}/${version}/overview`;\n"],"names":[],"mappings":";;AAMO,MAAM,eAAA,GAAkB;AAGxB,MAAM,eAA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CAAA,OAAA,EAAU,QAAQ,IAAI,OAAO,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/urls.esm.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const DEFAULT_API_URL = "https://api.massdriver.cloud";
|
|
2
|
+
const DEFAULT_APP_URL = "https://app.massdriver.cloud";
|
|
3
|
+
const GRAPHQL_PATH = "/api/v2/graphql";
|
|
4
|
+
const trimTrailingSlash = (url) => url.replace(/\/+$/, "");
|
|
5
|
+
const SOCKET_PATH = "/api/socket";
|
|
6
|
+
const socketUrl = (baseUrl = DEFAULT_API_URL) => {
|
|
7
|
+
const swapped = trimTrailingSlash(baseUrl).replace(
|
|
8
|
+
/^http(s?):\/\//,
|
|
9
|
+
"ws$1://"
|
|
10
|
+
);
|
|
11
|
+
return `${swapped}${SOCKET_PATH}`;
|
|
12
|
+
};
|
|
13
|
+
const parseEnvironmentId = (environmentId) => {
|
|
14
|
+
const [projectId, scopedEnvironmentId] = environmentId.split("-");
|
|
15
|
+
return { projectId, scopedEnvironmentId };
|
|
16
|
+
};
|
|
17
|
+
const composeEnvironmentId = (projectId, scopedEnvironmentId) => `${projectId}-${scopedEnvironmentId}`;
|
|
18
|
+
const parseInstanceId = (instanceId) => {
|
|
19
|
+
const [projectId, scopedEnvironmentId, scopedComponentId] = instanceId.split("-");
|
|
20
|
+
return { projectId, scopedEnvironmentId, scopedComponentId };
|
|
21
|
+
};
|
|
22
|
+
const parseComponentId = (componentId) => {
|
|
23
|
+
const [projectId, scopedComponentId] = componentId.split("-");
|
|
24
|
+
return { projectId, scopedComponentId };
|
|
25
|
+
};
|
|
26
|
+
const composeInstanceId = (projectId, scopedEnvironmentId, scopedComponentId) => `${projectId}-${scopedEnvironmentId}-${scopedComponentId}`;
|
|
27
|
+
const graphqlUrl = (baseUrl = DEFAULT_API_URL) => `${trimTrailingSlash(baseUrl)}${GRAPHQL_PATH}`;
|
|
28
|
+
const projectsUrl = (appUrl, orgId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/projects`;
|
|
29
|
+
const projectUrl = (appUrl, orgId, projectId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/projects/${projectId}`;
|
|
30
|
+
const environmentUrl = (appUrl, orgId, environmentId) => {
|
|
31
|
+
const { projectId, scopedEnvironmentId } = parseEnvironmentId(environmentId);
|
|
32
|
+
return `${projectUrl(
|
|
33
|
+
appUrl,
|
|
34
|
+
orgId,
|
|
35
|
+
projectId
|
|
36
|
+
)}/environments/${scopedEnvironmentId}`;
|
|
37
|
+
};
|
|
38
|
+
const instanceUrl = (appUrl, orgId, instanceId) => {
|
|
39
|
+
const { projectId, scopedEnvironmentId, scopedComponentId } = parseInstanceId(instanceId);
|
|
40
|
+
return `${trimTrailingSlash(
|
|
41
|
+
appUrl
|
|
42
|
+
)}/orgs/${orgId}/projects/${projectId}/environments/${scopedEnvironmentId}/instances/${scopedComponentId}`;
|
|
43
|
+
};
|
|
44
|
+
const instanceTabUrl = (appUrl, orgId, instanceId, tab) => `${instanceUrl(appUrl, orgId, instanceId)}?tab=${tab}`;
|
|
45
|
+
const instanceActionUrl = (appUrl, orgId, instanceId, action) => `${instanceUrl(appUrl, orgId, instanceId)}?action=${action}`;
|
|
46
|
+
const reposUrl = (appUrl, orgId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos`;
|
|
47
|
+
const repoUrl = (appUrl, orgId, repoId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos/${encodeURIComponent(
|
|
48
|
+
repoId
|
|
49
|
+
)}/all`;
|
|
50
|
+
const repoTabUrl = (appUrl, orgId, repoId, version, tab) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos/${encodeURIComponent(
|
|
51
|
+
repoId
|
|
52
|
+
)}/${encodeURIComponent(version)}/${tab}`;
|
|
53
|
+
const resourcesUrl = (appUrl, orgId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources`;
|
|
54
|
+
const resourceTabUrl = (appUrl, orgId, resourceId, tab) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources/${encodeURIComponent(
|
|
55
|
+
resourceId
|
|
56
|
+
)}/${tab}`;
|
|
57
|
+
const resourceUrl = (appUrl, orgId, resourceId) => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources/${encodeURIComponent(
|
|
58
|
+
resourceId
|
|
59
|
+
)}/general`;
|
|
60
|
+
const repoVersionOverviewUrl = (appUrl, orgId, repoName, version) => `${trimTrailingSlash(
|
|
61
|
+
appUrl
|
|
62
|
+
)}/orgs/${orgId}/repos/${repoName}/${version}/overview`;
|
|
63
|
+
|
|
64
|
+
export { DEFAULT_API_URL, DEFAULT_APP_URL, GRAPHQL_PATH, SOCKET_PATH, composeEnvironmentId, composeInstanceId, environmentUrl, graphqlUrl, instanceActionUrl, instanceTabUrl, instanceUrl, parseComponentId, parseEnvironmentId, parseInstanceId, projectUrl, projectsUrl, repoTabUrl, repoUrl, repoVersionOverviewUrl, reposUrl, resourceTabUrl, resourceUrl, resourcesUrl, socketUrl };
|
|
65
|
+
//# sourceMappingURL=urls.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urls.esm.js","sources":["../src/urls.ts"],"sourcesContent":["/**\n * Default Massdriver SaaS origins. Overridable (e.g. for self-hosted instances)\n * via the `massdriver.baseUrl` / `massdriver.appUrl` config keys.\n *\n * @public\n */\nexport const DEFAULT_API_URL = 'https://api.massdriver.cloud';\n\n/** @public */\nexport const DEFAULT_APP_URL = 'https://app.massdriver.cloud';\n\n/**\n * Path of the v2 GraphQL endpoint on the API origin.\n *\n * @public\n */\nexport const GRAPHQL_PATH = '/api/v2/graphql';\n\nconst trimTrailingSlash = (url: string): string => url.replace(/\\/+$/, '');\n\n/**\n * Phoenix/Absinthe socket endpoint for a given API origin, mirroring the web\n * app's `socketLink` (which connects to `${WS_URL}/api/socket`). The API origin\n * uses `https`/`http`; the socket swaps it to `wss`/`ws`. Backend-only — the\n * service-account token is appended as a query param server-side (the browser\n * never opens this socket; it consumes the backend SSE relay instead).\n *\n * @public\n */\nexport const SOCKET_PATH = '/api/socket';\n\n/** @public */\nexport const socketUrl = (baseUrl: string = DEFAULT_API_URL): string => {\n const swapped = trimTrailingSlash(baseUrl).replace(\n /^http(s?):\\/\\//,\n 'ws$1://',\n );\n return `${swapped}${SOCKET_PATH}`;\n};\n\n/**\n * Massdriver composite IDs join hyphen-free segments with `-`:\n * - environment id: `{projectId}-{scopedEnvironmentId}`\n * - instance id: `{projectId}-{scopedEnvironmentId}-{scopedComponentId}`\n *\n * The web app's URLs are keyed by the scoped segments, so deep-links are built\n * by splitting the composite id. Mirrors `apps/web/shared/utils/ids.js`.\n *\n * @public\n */\nexport const parseEnvironmentId = (\n environmentId: string,\n): { projectId: string; scopedEnvironmentId: string } => {\n const [projectId, scopedEnvironmentId] = environmentId.split('-');\n return { projectId, scopedEnvironmentId };\n};\n\n/**\n * Compose a full environment id from its parts: `{projectId}-{scopedEnvironmentId}`.\n *\n * @public\n */\nexport const composeEnvironmentId = (\n projectId: string,\n scopedEnvironmentId: string,\n): string => `${projectId}-${scopedEnvironmentId}`;\n\n/** @public */\nexport const parseInstanceId = (\n instanceId: string,\n): {\n projectId: string;\n scopedEnvironmentId: string;\n scopedComponentId: string;\n} => {\n const [projectId, scopedEnvironmentId, scopedComponentId] =\n instanceId.split('-');\n return { projectId, scopedEnvironmentId, scopedComponentId };\n};\n\n/**\n * Component ids are project-scoped: `{projectId}-{scopedComponentId}`. Mirrors\n * `apps/web/shared/utils/ids.js` `parseComponentId`.\n *\n * @public\n */\nexport const parseComponentId = (\n componentId: string,\n): { projectId: string; scopedComponentId: string } => {\n const [projectId, scopedComponentId] = componentId.split('-');\n return { projectId, scopedComponentId };\n};\n\n/**\n * Compose a full instance id from its parts:\n * `{projectId}-{scopedEnvironmentId}-{scopedComponentId}`. Mirrors\n * `apps/web/shared/utils/ids.js` `composeInstanceId`.\n *\n * @public\n */\nexport const composeInstanceId = (\n projectId: string,\n scopedEnvironmentId: string,\n scopedComponentId: string,\n): string => `${projectId}-${scopedEnvironmentId}-${scopedComponentId}`;\n\n/**\n * Full URL of the v2 GraphQL endpoint for a given API origin.\n *\n * @public\n */\nexport const graphqlUrl = (baseUrl: string = DEFAULT_API_URL): string =>\n `${trimTrailingSlash(baseUrl)}${GRAPHQL_PATH}`;\n\n/**\n * Deep-link into the Massdriver web app's projects list.\n *\n * @public\n */\nexport const projectsUrl = (appUrl: string, orgId: string): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/projects`;\n\n/**\n * Deep-link into the Massdriver web app for a project.\n *\n * @public\n */\nexport const projectUrl = (\n appUrl: string,\n orgId: string,\n projectId: string,\n): string => `${trimTrailingSlash(appUrl)}/orgs/${orgId}/projects/${projectId}`;\n\n/**\n * Deep-link into the Massdriver web app for an environment (its graph view).\n *\n * @public\n */\nexport const environmentUrl = (\n appUrl: string,\n orgId: string,\n environmentId: string,\n): string => {\n const { projectId, scopedEnvironmentId } = parseEnvironmentId(environmentId);\n return `${projectUrl(\n appUrl,\n orgId,\n projectId,\n )}/environments/${scopedEnvironmentId}`;\n};\n\n/**\n * Deep-link into the Massdriver web app for a deployed instance's detail panel.\n *\n * @public\n */\nexport const instanceUrl = (\n appUrl: string,\n orgId: string,\n instanceId: string,\n): string => {\n const { projectId, scopedEnvironmentId, scopedComponentId } =\n parseInstanceId(instanceId);\n return `${trimTrailingSlash(\n appUrl,\n )}/orgs/${orgId}/projects/${projectId}/environments/${scopedEnvironmentId}/instances/${scopedComponentId}`;\n};\n\n/**\n * Deep-link to a specific tab of an instance's detail panel in the web app,\n * e.g. `?tab=overview` (change version) or `?tab=secrets` (set/clear secret).\n *\n * @public\n */\nexport const instanceTabUrl = (\n appUrl: string,\n orgId: string,\n instanceId: string,\n tab: string,\n): string => `${instanceUrl(appUrl, orgId, instanceId)}?tab=${tab}`;\n\n/**\n * Deep-link that opens one of the instance panel's action dialogs in the web\n * app (`?action=copy | decommission | delete`), mirroring the app's\n * `useDialogParam('action')`.\n *\n * @public\n */\nexport const instanceActionUrl = (\n appUrl: string,\n orgId: string,\n instanceId: string,\n action: 'copy' | 'decommission' | 'delete',\n): string => `${instanceUrl(appUrl, orgId, instanceId)}?action=${action}`;\n\n/**\n * Deep-link into the Massdriver web app's repositories list.\n *\n * @public\n */\nexport const reposUrl = (appUrl: string, orgId: string): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos`;\n\n/**\n * Deep-link to a repository's default view in the web app:\n * `/orgs/{orgId}/repos/{repoId}/all` (the \"all versions\" view, matching the\n * app's repo list link target).\n *\n * @public\n */\nexport const repoUrl = (\n appUrl: string,\n orgId: string,\n repoId: string,\n): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos/${encodeURIComponent(\n repoId,\n )}/all`;\n\n/**\n * Deep-link to a specific tab of a repository version in the web app:\n * `/orgs/{orgId}/repos/{repoId}/{version}/{tab}`. Version is `all` for the\n * all-versions view.\n *\n * @public\n */\nexport const repoTabUrl = (\n appUrl: string,\n orgId: string,\n repoId: string,\n version: string,\n tab: string,\n): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/repos/${encodeURIComponent(\n repoId,\n )}/${encodeURIComponent(version)}/${tab}`;\n\n/**\n * Deep-link into the Massdriver web app's resources list.\n *\n * @public\n */\nexport const resourcesUrl = (appUrl: string, orgId: string): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources`;\n\n/**\n * Deep-link to a specific tab of a resource's detail page in the web app:\n * `/orgs/{orgId}/resources/{resourceId}/{tab}`.\n *\n * @public\n */\nexport const resourceTabUrl = (\n appUrl: string,\n orgId: string,\n resourceId: string,\n tab: string,\n): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources/${encodeURIComponent(\n resourceId,\n )}/${tab}`;\n\n/**\n * Deep-link to a cloud resource's detail page in the web app:\n * `/orgs/{orgId}/resources/{resourceId}/general`. Used by the instance\n * Dependencies/Resources tabs' \"fulfilled by\" / resource-name links.\n *\n * @public\n */\nexport const resourceUrl = (\n appUrl: string,\n orgId: string,\n resourceId: string,\n): string =>\n `${trimTrailingSlash(appUrl)}/orgs/${orgId}/resources/${encodeURIComponent(\n resourceId,\n )}/general`;\n\n/**\n * Deep-link to a bundle/OCI-repo version's overview in the web app:\n * `/orgs/{orgId}/repos/{repoName}/{version}/overview`. Used by the instance\n * Overview tab's \"view in repository\" link.\n *\n * @public\n */\nexport const repoVersionOverviewUrl = (\n appUrl: string,\n orgId: string,\n repoName: string,\n version: string,\n): string =>\n `${trimTrailingSlash(\n appUrl,\n )}/orgs/${orgId}/repos/${repoName}/${version}/overview`;\n"],"names":[],"mappings":"AAMO,MAAM,eAAA,GAAkB;AAGxB,MAAM,eAAA,GAAkB;AAOxB,MAAM,YAAA,GAAe;AAE5B,MAAM,oBAAoB,CAAC,GAAA,KAAwB,GAAA,CAAI,OAAA,CAAQ,QAAQ,EAAE,CAAA;AAWlE,MAAM,WAAA,GAAc;AAGpB,MAAM,SAAA,GAAY,CAAC,OAAA,GAAkB,eAAA,KAA4B;AACtE,EAAA,MAAM,OAAA,GAAU,iBAAA,CAAkB,OAAO,CAAA,CAAE,OAAA;AAAA,IACzC,gBAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,CAAA,EAAG,OAAO,CAAA,EAAG,WAAW,CAAA,CAAA;AACjC;AAYO,MAAM,kBAAA,GAAqB,CAChC,aAAA,KACuD;AACvD,EAAA,MAAM,CAAC,SAAA,EAAW,mBAAmB,CAAA,GAAI,aAAA,CAAc,MAAM,GAAG,CAAA;AAChE,EAAA,OAAO,EAAE,WAAW,mBAAA,EAAoB;AAC1C;AAOO,MAAM,uBAAuB,CAClC,SAAA,EACA,wBACW,CAAA,EAAG,SAAS,IAAI,mBAAmB,CAAA;AAGzC,MAAM,eAAA,GAAkB,CAC7B,UAAA,KAKG;AACH,EAAA,MAAM,CAAC,SAAA,EAAW,mBAAA,EAAqB,iBAA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A,EACA,KAAA,EACA,UAAA,EACA,GAAA,KAEA,CAAA,EAAG,iBAAA,CAAkB,MAAM,CAAC,CAAA,MAAA,EAAS,KAAK,CAAA,WAAA,EAAc,kBAAA;AAAA,EACtD;AACF,CAAC,IAAI,GAAG,CAAA;AASH,MAAM,WAAA,GAAc,CACzB,MAAA,EACA,KAAA,EACA,UAAA,KAEA,CAAA,EAAG,iBAAA,CAAkB,MAAM,CAAC,CAAA,MAAA,EAAS,KAAK,CAAA,WAAA,EAAc,kBAAA;AAAA,EACtD;AACF,CAAC,CAAA,QAAA;AASI,MAAM,yBAAyB,CACpC,MAAA,EACA,KAAA,EACA,QAAA,EACA,YAEA,CAAA,EAAG,iBAAA;AAAA,EACD;AACF,CAAC,CAAA,MAAA,EAAS,KAAK,CAAA,OAAA,EAAU,QAAQ,IAAI,OAAO,CAAA,SAAA;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@massdriver/backstage-plugin-common",
|
|
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-common"
|
|
9
|
+
},
|
|
10
|
+
"description": "Common functionalities for the massdriver plugin",
|
|
11
|
+
"main": "dist/index.cjs.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"main": "dist/index.cjs.js",
|
|
16
|
+
"module": "dist/index.esm.js",
|
|
17
|
+
"types": "dist/index.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"backstage": {
|
|
20
|
+
"role": "common-library",
|
|
21
|
+
"pluginId": "massdriver",
|
|
22
|
+
"pluginPackages": [
|
|
23
|
+
"@massdriver/backstage-plugin",
|
|
24
|
+
"@massdriver/backstage-plugin-backend",
|
|
25
|
+
"@massdriver/backstage-plugin-common"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"configSchema": "config.d.ts",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@backstage/config": "^1.3.8"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "backstage-cli package build",
|
|
35
|
+
"lint": "backstage-cli package lint",
|
|
36
|
+
"test": "backstage-cli package test",
|
|
37
|
+
"clean": "backstage-cli package clean",
|
|
38
|
+
"prepack": "backstage-cli package prepack",
|
|
39
|
+
"postpack": "backstage-cli package postpack"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@backstage/cli": "^0.36.3"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"typesVersions": {
|
|
48
|
+
"*": {
|
|
49
|
+
"package.json": [
|
|
50
|
+
"package.json"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"module": "dist/index.esm.js"
|
|
55
|
+
}
|