Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphcool-yml

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphcool-yml - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

dist/constants.d.ts

7

dist/Cluster.d.ts
import 'isomorphic-fetch';
import { GraphQLClient } from 'graphql-request';
export declare class Cluster {

@@ -7,5 +8,9 @@ name: string;

clusterSecret?: string;
requiresAuth: boolean;
private cachedToken?;
constructor(name: string, baseUrl: string, clusterSecret?: string, local?: boolean);
readonly token: string;
getToken(serviceName: string, workspaceSlug?: string, stageName?: string): Promise<string>;
getLocalToken(): string;
readonly cloudClient: GraphQLClient;
generateClusterToken(serviceName: string, workspaceSlug?: string, stageName?: string): Promise<string>;
getApiEndpoint(serviceName: string, stage: string): string;

@@ -12,0 +17,0 @@ getWSEndpoint(serviceName: string, stage: string): string;

74

dist/Cluster.js

@@ -41,2 +41,4 @@ "use strict";

var jwt = require("jsonwebtoken");
var constants_1 = require("./constants");
var graphql_request_1 = require("graphql-request");
var Cluster = /** @class */ (function () {

@@ -50,19 +52,36 @@ function Cluster(name, baseUrl, clusterSecret, local) {

}
Object.defineProperty(Cluster.prototype, "token", {
Cluster.prototype.getToken = function (serviceName, workspaceSlug, stageName) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!this.clusterSecret) {
return [2 /*return*/, ''];
}
// public clusters just take the token
if (this.local) {
return [2 /*return*/, this.getLocalToken()];
}
else {
return [2 /*return*/, this.generateClusterToken(serviceName, workspaceSlug, stageName)];
}
return [2 /*return*/];
});
});
};
Cluster.prototype.getLocalToken = function () {
if (!this.cachedToken) {
var grants = [{ target: "*/*/*", action: '*' }];
this.cachedToken = jwt.sign({ grants: grants }, this.clusterSecret, {
expiresIn: '10 minutes',
algorithm: 'RS256',
});
}
return this.cachedToken;
};
Object.defineProperty(Cluster.prototype, "cloudClient", {
get: function () {
if (!this.clusterSecret) {
return '';
}
// public clusters just take the token
if (!this.local) {
return this.clusterSecret;
}
if (!this.cachedToken) {
var grants = [{ target: "*/*/*", action: '*' }];
this.cachedToken = jwt.sign({ grants: grants }, this.clusterSecret, {
expiresIn: '10 minutes',
algorithm: 'RS256',
});
}
return this.cachedToken;
return new graphql_request_1.GraphQLClient(constants_1.cloudApiEndpoint, {
headers: {
Authorization: "Bearer " + this.clusterSecret,
},
});
},

@@ -72,2 +91,25 @@ enumerable: true,

});
Cluster.prototype.generateClusterToken = function (serviceName, workspaceSlug, stageName) {
if (workspaceSlug === void 0) { workspaceSlug = '*'; }
return __awaiter(this, void 0, void 0, function () {
var query, clusterToken;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
query = "\n mutation ($input: GenerateClusterTokenRequest!) {\n generateClusterToken(input: $input) {\n clusterToken\n }\n }\n ";
return [4 /*yield*/, this.cloudClient.request(query, {
input: {
workspaceSlug: workspaceSlug,
clusterName: this.name,
serviceName: serviceName,
stageName: stageName,
},
})];
case 1:
clusterToken = (_a.sent()).generateClusterToken.clusterToken;
return [2 /*return*/, clusterToken];
}
});
});
};
Cluster.prototype.getApiEndpoint = function (serviceName, stage) {

@@ -74,0 +116,0 @@ return this.baseUrl + "/" + serviceName + "/" + stage;

@@ -9,3 +9,5 @@ import { Args } from './types/common';

sharedClusters: string[];
sharedEndpoint: string;
clusterEndpointMap: {
[key: string]: string;
};
args: Args;

@@ -12,0 +14,0 @@ activeCluster: Cluster;

@@ -56,9 +56,10 @@ "use strict";

var debug = require('debug')('Environment');
var isDev = (process.env.ENV || '').toLowerCase() === 'dev';
var Environment = /** @class */ (function () {
function Environment(home, out) {
if (out === void 0) { out = new Output_1.Output(); }
this.sharedClusters = ['shared-public-demo'];
this.sharedEndpoint = (process.env.ENV || '').toLowerCase() === 'dev'
? 'https://dev.database-beta.graph.cool'
: 'https://database-beta.graph.cool';
this.sharedClusters = ['graphcool-eu1'];
this.clusterEndpointMap = {
'graphcool-eu1': 'https://graphcool-eu1.graphcool.cloud',
};
this.globalRC = {};

@@ -87,31 +88,4 @@ this.databaseRC = {};

return __awaiter(this, void 0, void 0, function () {
var res, json, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
return [4 /*yield*/, fetch('https://stats.graph.cool/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query: "{publicClusters}" }),
})];
case 1:
res = _a.sent();
return [4 /*yield*/, res.json()];
case 2:
json = _a.sent();
if (json.data.publicClusters &&
Array.isArray(json.data.publicClusters) &&
json.data.publicClusters.length > 0) {
this.sharedClusters = json.data.publicClusters;
}
return [3 /*break*/, 4];
case 3:
e_1 = _a.sent();
console.error(e_1);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
return [2 /*return*/];
});

@@ -228,3 +202,3 @@ });

return this.sharedClusters.map(function (clusterName) {
return new Cluster_1.Cluster(clusterName, _this.sharedEndpoint, rc && rc.cloudSessionKey, false);
return new Cluster_1.Cluster(clusterName, _this.clusterEndpointMap[clusterName], rc && rc.cloudSessionKey, false);
});

@@ -231,0 +205,0 @@ };

@@ -21,6 +21,9 @@ import { GraphcoolDefinition } from 'graphcool-json-schema';

load(args: Args, envPath?: string): Promise<void>;
validate(): void;
getToken(serviceName: string, stageName: string): string | undefined;
getCluster(): Cluster | undefined;
getTypesString(definition: GraphcoolDefinition): string;
getClusterName(): string | null;
getWorkspace(): string | null;
addCluster(cluster: string, args: any): Promise<void>;
}

@@ -57,3 +57,3 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var _a, secrets, disableAuth;
var _a, secrets;
return __generator(this, function (_b) {

@@ -72,6 +72,3 @@ switch (_b.label) {

this.secrets = secrets ? secrets.replace(/\s/g, '').split(',') : null;
disableAuth = this.definition.disableAuth;
if (this.secrets === null && !disableAuth) {
throw new Error('Please either provide a secret in your graphcool.yml or disableAuth: true');
}
this.validate();
_b.label = 2;

@@ -83,2 +80,16 @@ case 2: return [2 /*return*/];

};
GraphcoolDefinitionClass.prototype.validate = function () {
var disableAuth = this.definition.disableAuth;
if (this.secrets === null && !disableAuth) {
throw new Error('Please either provide a secret in your graphcool.yml or disableAuth: true');
}
// shared clusters need a workspace
var clusterName = this.getClusterName();
if (clusterName &&
this.env.sharedClusters.includes(clusterName) &&
!this.getWorkspace()) {
throw new Error("You provided the cluster " + clusterName + ", but it needs to be prepended with the workspace you want to deploy to");
}
this.env.sharedClusters;
};
GraphcoolDefinitionClass.prototype.getToken = function (serviceName, stageName) {

@@ -99,5 +110,6 @@ if (this.secrets) {

GraphcoolDefinitionClass.prototype.getCluster = function () {
if (this.definition && this.definition.cluster) {
var cluster = this.env.clusterByName(this.definition.cluster);
if (!cluster && this.definition.cluster !== 'local') {
var clusterName = this.getClusterName();
if (clusterName) {
var cluster = this.env.clusterByName(clusterName);
if (!cluster && clusterName !== 'local') {
throw new Error("Cluster " + cluster + ", that is provided in the graphcoo.yml could not be found.");

@@ -128,2 +140,17 @@ }

};
GraphcoolDefinitionClass.prototype.getClusterName = function () {
if (this.definition && this.definition.cluster) {
return this.definition.cluster.split('/').slice(-1)[0];
}
return null;
};
GraphcoolDefinitionClass.prototype.getWorkspace = function () {
if (this.definition && this.definition.cluster) {
var splitted = this.definition.cluster.split('/');
if (splitted.length > 1) {
return splitted[0];
}
}
return null;
};
GraphcoolDefinitionClass.prototype.addCluster = function (cluster, args) {

@@ -130,0 +157,0 @@ return __awaiter(this, void 0, void 0, function () {

{
"name": "graphcool-yml",
"version": "0.3.0",
"version": "0.4.0",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc