wgc
Version:
The official CLI tool to manage the GraphQL Federation Platform Cosmo
45 lines • 1.99 kB
JavaScript
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb';
import { getBaseHeaders } from './config.js';
/**
* Creates a router token for a federated graph.
* Never calls program.error() — caller decides how to handle errors.
*/
export async function createRouterToken(params) {
var _a, _b, _c;
const { client, tokenName, graphName, namespace } = params;
const resp = await client.platform.createFederatedGraphToken({
tokenName,
graphName,
namespace,
}, {
headers: getBaseHeaders(),
});
if (((_a = resp.response) === null || _a === void 0 ? void 0 : _a.code) === EnumStatusCode.OK) {
return { error: null, token: resp.token };
}
return { error: new Error((_c = (_b = resp.response) === null || _b === void 0 ? void 0 : _b.details) !== null && _c !== void 0 ? _c : 'Could not create router token') };
}
/**
* Deletes a router token. Idempotent — returns success if token doesn't exist.
* Never calls program.error() — caller decides how to handle errors.
*/
export async function deleteRouterToken(params) {
var _a, _b, _c, _d, _e;
const { client, tokenName, graphName, namespace } = params;
const resp = await client.platform.deleteRouterToken({
tokenName,
fedGraphName: graphName,
namespace,
}, {
headers: getBaseHeaders(),
});
if (((_a = resp.response) === null || _a === void 0 ? void 0 : _a.code) === EnumStatusCode.OK) {
return { error: null };
}
// Treat "doesn't exist" as success (idempotent)
if ((_c = (_b = resp.response) === null || _b === void 0 ? void 0 : _b.details) === null || _c === void 0 ? void 0 : _c.includes("doesn't exist")) {
return { error: null };
}
return { error: new Error((_e = (_d = resp.response) === null || _d === void 0 ? void 0 : _d.details) !== null && _e !== void 0 ? _e : 'Could not delete router token') };
}
//# sourceMappingURL=router-token.js.map