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

@anaqor/planqk

Package Overview
Dependencies
Maintainers
2
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anaqor/planqk - npm Package Compare versions

Comparing version 1.10.1 to 1.11.0-alpha.1

dist/client/apis/index.d.ts

12

dist/commands/init/index.js

@@ -50,2 +50,10 @@ "use strict";

{
name: 'D-Wave Leap Starter (own access token required)',
value: {
path: 'python/python-starter-dwave',
runtime: managed_service_config_1.Runtime.PYTHON_TEMPLATE,
quantumBackend: managed_service_config_1.QuantumBackend.DWAVE,
},
},
{
name: 'Docker Go Starter',

@@ -184,4 +192,2 @@ value: { path: 'docker/docker-go', runtime: managed_service_config_1.Runtime.DOCKER, quantumBackend: managed_service_config_1.QuantumBackend.NONE },

}
// replace global variables
readmeContent = readmeContent.replace(/\${PROJECT_NAME}/g, projectName);
// replace variables

@@ -191,2 +197,4 @@ for (const variable of variables) {

}
// replace global variables
readmeContent = readmeContent.replace(/\${PROJECT_NAME}/g, projectName);
fs_extra_1.default.writeFileSync(readmeFileLocation, readmeContent);

@@ -193,0 +201,0 @@ }

10

dist/commands/run/index.js

@@ -9,6 +9,6 @@ "use strict";

const async_wait_until_1 = tslib_1.__importDefault(require("async-wait-until"));
const jobDto_1 = require("../../client/model/jobDto");
const command_1 = require("../../model/command");
const planqk_service_1 = tslib_1.__importDefault(require("../../service/planqk-service"));
const service_config_service_1 = require("../../service/service-config-service");
const client_1 = require("../../client");
class Run extends command_1.AuthenticatedCommand {

@@ -55,3 +55,3 @@ async init() {

job = await this.planqkService.getJobById(job.id);
return job.status === jobDto_1.JobDto.StatusEnum.Succeeded || job.status === jobDto_1.JobDto.StatusEnum.Failed || job.status === jobDto_1.JobDto.StatusEnum.Cancelled;
return job.status === client_1.JobDtoStatusEnum.Succeeded || job.status === client_1.JobDtoStatusEnum.Failed || job.status === client_1.JobDtoStatusEnum.Cancelled;
}, {

@@ -66,11 +66,11 @@ timeout: 10 * 60 * 1000,

const jobDetailsLink = `https://platform.planqk.de/jobs/${job.id}`;
if (job.status === jobDto_1.JobDto.StatusEnum.Succeeded) {
if (job.status === client_1.JobDtoStatusEnum.Succeeded) {
core_1.ux.action.stop('Job succeeded.');
core_1.ux.info(`See result at \u001B]8;;${jobDetailsLink}\u0007${jobDetailsLink}\u001B]8;;\u0007\``);
}
else if (job.status === jobDto_1.JobDto.StatusEnum.Failed) {
else if (job.status === client_1.JobDtoStatusEnum.Failed) {
core_1.ux.action.stop('Job failed.');
core_1.ux.info(`See details at \u001B]8;;${jobDetailsLink}\u0007${jobDetailsLink}\u001B]8;;\u0007\``);
}
else if (job.status === jobDto_1.JobDto.StatusEnum.Cancelled) {
else if (job.status === client_1.JobDtoStatusEnum.Cancelled) {
core_1.ux.action.stop('Job canceled.');

@@ -77,0 +77,0 @@ core_1.ux.info(`See details at \u001B]8;;${jobDetailsLink}\u0007${jobDetailsLink}\u001B]8;;\u0007\``);

@@ -11,6 +11,6 @@ "use strict";

const command_1 = require("../../model/command");
const buildJobDto_1 = require("../../client/model/buildJobDto");
const planqk_service_1 = tslib_1.__importDefault(require("../../service/planqk-service"));
const validationResult_1 = require("../../client/model/validationResult");
const service_config_service_1 = require("../../service/service-config-service");
const stream_to_blob_1 = require("../../helper/stream-to-blob");
const client_1 = require("../../client");
class Up extends command_1.AuthenticatedCommand {

@@ -25,2 +25,3 @@ async init() {

const userCode = await this.zipUserCode();
const blob = await (0, stream_to_blob_1.streamToBlob)(userCode);
let updateMode = false;

@@ -35,3 +36,3 @@ const silentMode = flags.silent;

updateMode = true;
service = await this.planqkService.updateService(serviceConfig.serviceId, userCode);
service = await this.planqkService.updateService(serviceConfig.serviceId, blob);
}

@@ -42,3 +43,3 @@ else {

}
service = await this.planqkService.createService(serviceConfig, userCode);
service = await this.planqkService.createService(serviceConfig, blob);
serviceConfig.serviceId = service === null || service === void 0 ? void 0 : service.id;

@@ -57,10 +58,10 @@ (0, service_config_service_1.writeServiceConfig)(process.cwd(), serviceConfig);

if (!silentMode) {
if (buildJob.step === buildJobDto_1.BuildJobDto.StepEnum.BuildImage) {
if (buildJob.step === client_1.BuildJobDtoStepEnum.BuildImage) {
core_1.ux.action.start('Building Image (1/2)');
}
else if (buildJob.step === buildJobDto_1.BuildJobDto.StepEnum.PushImage) {
else if (buildJob.step === client_1.BuildJobDtoStepEnum.PushImage) {
core_1.ux.action.start('Pushing Image (2/2)');
}
}
return buildJob.status === buildJobDto_1.BuildJobDto.StatusEnum.Success || buildJob.status === buildJobDto_1.BuildJobDto.StatusEnum.Failure;
return buildJob.status === client_1.BuildJobDtoStatusEnum.Success || buildJob.status === client_1.BuildJobDtoStatusEnum.Failure;
}, {

@@ -75,3 +76,3 @@ timeout: 10 * 60 * 1000,

}
if (buildJob && buildJob.status === buildJobDto_1.BuildJobDto.StatusEnum.Success) {
if (buildJob && buildJob.status === client_1.BuildJobDtoStatusEnum.Success) {
let msg = 'Service created \u{1F680}';

@@ -88,6 +89,6 @@ if (updateMode) {

}
else if (buildJob && buildJob.status === buildJobDto_1.BuildJobDto.StatusEnum.Failure) {
else if (buildJob && buildJob.status === client_1.BuildJobDtoStatusEnum.Failure) {
const { validationResult } = buildJob;
let reason = 'Failed creating service';
if ((validationResult === null || validationResult === void 0 ? void 0 : validationResult.state) === validationResult_1.ValidationResult.StateEnum.Error && validationResult.summary) {
if ((validationResult === null || validationResult === void 0 ? void 0 : validationResult.state) === client_1.ValidationResultStateEnum.Error && validationResult.summary) {
reason = `${reason}: ${validationResult.summary}`;

@@ -94,0 +95,0 @@ }

@@ -5,3 +5,2 @@ "use strict";

const tslib_1 = require("tslib");
const axios_1 = tslib_1.__importDefault(require("axios"));
const adm_zip_1 = tslib_1.__importDefault(require("adm-zip"));

@@ -20,4 +19,5 @@ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));

try {
const t = await axios_1.default.get('https://github.com/PlanQK/planqk-platform-samples/archive/refs/heads/master.zip', config);
zip = new adm_zip_1.default(t.data, {});
const response = await fetch('https://github.com/PlanQK/planqk-platform-samples/archive/refs/heads/master.zip', config);
const buffer = await response.arrayBuffer();
zip = new adm_zip_1.default(Buffer.from(buffer), {});
}

@@ -24,0 +24,0 @@ catch (error) {

@@ -10,3 +10,5 @@ export declare enum AuthType {

basePath: string;
defaultHeaders: Record<string, unknown>;
defaultHeaders: {
[key: string]: string;
};
}

@@ -13,0 +15,0 @@ export interface Context {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const user_config_1 = require("../model/user-config");
const axios_1 = tslib_1.__importStar(require("axios"));
class AuthService {

@@ -14,10 +12,10 @@ constructor(config, userConfig) {

const basePath = ((_a = this.userConfig.endpoint) === null || _a === void 0 ? void 0 : _a.basePath) || user_config_1.defaultBasePath;
const payload = await axios_1.default.post(basePath + '/authorize', undefined, { headers: { 'X-Auth-Token': apiKey } });
return payload.data;
const payload = await fetch(basePath + '/authorize', {
method: 'POST',
headers: { 'X-Auth-Token': apiKey },
});
return (await payload.json());
}
catch (error) {
if (error instanceof axios_1.AxiosError && error.status === 401) {
throw new Error('Invalid credentials. Please try again.');
}
throw new Error(`Internal error occurred, please contact your PlanQK administrator: ${error}`);
catch {
throw new Error('Internal error occurred, please contact your PlanQK administrator');
}

@@ -24,0 +22,0 @@ }

@@ -1,16 +0,8 @@

/// <reference types="node" />
import { Command } from '@oclif/core';
import { Config } from '@oclif/core/lib/config';
import { CommandService } from './command-service';
import Account from '../model/account';
import UserConfig from '../model/user-config';
import { CommandService } from './command-service';
import { ServicePlatformServicesApi } from '../client/api/servicePlatformServicesApi';
import { ServiceDto } from '../client/model/serviceDto';
import { BuildJobDto, ServiceDefinitionDto } from '../client/model/models';
import { HttpError } from '../client/api/apis';
import { ReadStream } from 'fs-extra';
import ManagedServiceConfig from '../model/managed-service-config';
import { ServicePlatformJobsApi } from '../client/api/servicePlatformJobsApi';
import { CreateJobRequest } from '../client/model/createJobRequest';
import { JobDto } from '../client/model/jobDto';
import Account from '../model/account';
import { BuildJobDto, CreateJobRequest, JobDto, ServiceDefinitionDto, ServiceDto, ServiceOverviewDto, ServicePlatformJobsApi, ServicePlatformServicesApi } from '../client';
export default class PlanqkService extends CommandService {

@@ -20,6 +12,6 @@ serviceApi: ServicePlatformServicesApi;

constructor(cmd: Command, config: Config, userConfig: UserConfig);
getServices(): Promise<ServiceDto[]>;
getServices(): Promise<ServiceOverviewDto[]>;
getService(id: string): Promise<ServiceDto>;
createService(serviceConfig: ManagedServiceConfig, userCode: ReadStream): Promise<ServiceDto>;
updateService(serviceId: string, userCode: ReadStream): Promise<ServiceDto>;
createService(serviceConfig: ManagedServiceConfig, userCode: Blob): Promise<ServiceDto>;
updateService(serviceId: string, userCode: Blob): Promise<ServiceDto>;
getBuildJob(service: ServiceDto, serviceDefinition: ServiceDefinitionDto): Promise<BuildJobDto>;

@@ -29,3 +21,2 @@ runJob(payload: CreateJobRequest): Promise<JobDto>;

getAccounts(): Promise<Account[]>;
getErrorMessage(error: HttpError): string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_service_1 = require("./command-service");
const user_config_1 = require("../model/user-config");
const command_service_1 = require("./command-service");
const servicePlatformServicesApi_1 = require("../client/api/servicePlatformServicesApi");
const apis_1 = require("../client/api/apis");
const managed_service_config_1 = require("../model/managed-service-config");
const servicePlatformJobsApi_1 = require("../client/api/servicePlatformJobsApi");
const axios_1 = tslib_1.__importDefault(require("axios"));
const client_1 = require("../client");
// TODO: Handle fetch errors
// const response = await fetch(input, init);
// if (!response.ok) {
// throw new MptError(response);
// }
// return response;
class PlanqkService extends command_service_1.CommandService {

@@ -15,13 +17,15 @@ constructor(cmd, config, userConfig) {

super(cmd, config, userConfig);
const apiKey = (_a = userConfig.auth) === null || _a === void 0 ? void 0 : _a.value;
this.serviceApi = new servicePlatformServicesApi_1.ServicePlatformServicesApi();
this.serviceApi.setApiKey(servicePlatformServicesApi_1.ServicePlatformServicesApiApiKeys.apiKey, apiKey);
this.jobApi = new servicePlatformJobsApi_1.ServicePlatformJobsApi();
this.jobApi.setApiKey(servicePlatformJobsApi_1.ServicePlatformJobsApiApiKeys.apiKey, apiKey);
const basePath = ((_b = userConfig.endpoint) === null || _b === void 0 ? void 0 : _b.basePath) || user_config_1.defaultBasePath;
const defaultHeaders = ((_c = userConfig.endpoint) === null || _c === void 0 ? void 0 : _c.defaultHeaders) || {};
this.serviceApi.basePath = basePath;
this.serviceApi.defaultHeaders = defaultHeaders;
this.jobApi.basePath = basePath;
this.jobApi.defaultHeaders = defaultHeaders;
const basePath = ((_a = userConfig.endpoint) === null || _a === void 0 ? void 0 : _a.basePath) || user_config_1.defaultBasePath;
const defaultHeaders = ((_b = userConfig.endpoint) === null || _b === void 0 ? void 0 : _b.defaultHeaders) || {};
const apiKey = (_c = userConfig.auth) === null || _c === void 0 ? void 0 : _c.value;
this.serviceApi = new client_1.ServicePlatformServicesApi(new client_1.Configuration({
apiKey: apiKey,
basePath: basePath,
headers: defaultHeaders,
}));
this.jobApi = new client_1.ServicePlatformJobsApi(new client_1.Configuration({
apiKey: apiKey,
basePath: basePath,
headers: defaultHeaders,
}));
}

@@ -32,10 +36,5 @@ async getServices() {

const organizationId = ((_a = this.userConfig.context) === null || _a === void 0 ? void 0 : _a.isOrganization) ? this.userConfig.context.id : undefined;
const response = await this.serviceApi.getServices(undefined, organizationId);
return response.body;
return await this.serviceApi.getServices({ xOrganizationId: organizationId });
}
catch (error) {
if (error instanceof apis_1.HttpError) {
const errorMessage = this.getErrorMessage(error);
this.cmd.error(`Error getting services: ${errorMessage}`);
}
catch {
throw new Error('Internal error occurred, please contact your PlanQK administrator');

@@ -48,13 +47,5 @@ }

const organizationId = ((_a = this.userConfig.context) === null || _a === void 0 ? void 0 : _a.isOrganization) ? this.userConfig.context.id : undefined;
const response = await this.serviceApi.getService(id, organizationId);
return response.body;
return await this.serviceApi.getService({ id, xOrganizationId: organizationId });
}
catch (error) {
if (error instanceof apis_1.HttpError) {
if (error.response.statusCode === 404) {
this.cmd.error(`Service with id ${id} not found. Deploy your service by running 'planqk up' first.`);
}
const errorMessage = this.getErrorMessage(error);
this.cmd.error(`Error getting service: ${errorMessage}`);
}
catch {
throw new Error('Internal error occurred, please contact your PlanQK administrator');

@@ -65,4 +56,4 @@ }

var _a, _b, _c, _d, _e, _f, _g;
const vCpuMilli = (((_a = serviceConfig.resources) === null || _a === void 0 ? void 0 : _a.cpu) || 1) * 1000;
const memoryMegabyte = (((_b = serviceConfig.resources) === null || _b === void 0 ? void 0 : _b.memory) || 2) * 1024;
const milliCpus = (((_a = serviceConfig.resources) === null || _a === void 0 ? void 0 : _a.cpu) || 1) * 1000;
const memoryInMegabytes = (((_b = serviceConfig.resources) === null || _b === void 0 ? void 0 : _b.memory) || 2) * 1024;
const gpuAccelerator = ((_d = (_c = serviceConfig.resources) === null || _c === void 0 ? void 0 : _c.gpu) === null || _d === void 0 ? void 0 : _d.type) || 'NONE';

@@ -75,14 +66,17 @@ const gpuCount = ((_f = (_e = serviceConfig.resources) === null || _e === void 0 ? void 0 : _e.gpu) === null || _f === void 0 ? void 0 : _f.count) || 0;

try {
const payload = await this.serviceApi.createManagedService(serviceConfig.name, serviceConfig.description, serviceConfig.quantumBackend, usePlatformToken, vCpuMilli, memoryMegabyte, serviceConfig.runtime, gpuCount, gpuAccelerator, ((_g = this.userConfig.context) === null || _g === void 0 ? void 0 : _g.isOrganization) ? this.userConfig.context.id : undefined, userCode, undefined, {
headers: {
'Content-Type': 'multipart/form-data',
},
return await this.serviceApi.createManagedService({
name: serviceConfig.name,
description: serviceConfig.description,
quantumBackend: serviceConfig.quantumBackend,
usePlatformToken: usePlatformToken,
milliCpus: milliCpus,
memoryInMegabytes: memoryInMegabytes,
runtime: serviceConfig.runtime,
gpuCount: gpuCount,
gpuAccelerator: gpuAccelerator,
xOrganizationId: ((_g = this.userConfig.context) === null || _g === void 0 ? void 0 : _g.isOrganization) ? this.userConfig.context.id : undefined,
userCode: userCode,
});
return payload.body;
}
catch (error) {
if (error instanceof apis_1.HttpError) {
const errorMessage = this.getErrorMessage(error);
this.cmd.error(`Error processing request: ${errorMessage}`);
}
catch {
throw new Error('Internal error occurred, please contact your PlanQK administrator');

@@ -95,12 +89,13 @@ }

try {
const { body: service } = await this.serviceApi.getService(serviceId, organizationId);
const service = await this.serviceApi.getService({ id: serviceId, xOrganizationId: organizationId });
const serviceDefinition = service && service.serviceDefinitions && service.serviceDefinitions[0];
await this.serviceApi.updateSourceCode(serviceId, serviceDefinition.id, userCode, organizationId);
await this.serviceApi.updateSourceCode({
serviceId: serviceId,
versionId: serviceDefinition.id,
sourceCode: userCode,
xOrganizationId: organizationId,
});
return service;
}
catch (error) {
if (error instanceof apis_1.HttpError) {
const errorMessage = this.getErrorMessage(error);
this.cmd.error(`Error processing request: ${errorMessage}`);
}
catch {
throw new Error('Internal error occurred, please contact your PlanQK administrator');

@@ -112,20 +107,20 @@ }

const organizationId = ((_a = this.userConfig.context) === null || _a === void 0 ? void 0 : _a.isOrganization) ? this.userConfig.context.id : undefined;
const payload = await this.serviceApi.getBuildStatus(service.id, serviceDefinition.id, organizationId);
return payload.body;
try {
return await this.serviceApi.getBuildStatus({
serviceId: service.id,
versionId: serviceDefinition.id,
xOrganizationId: organizationId,
});
}
catch {
throw new Error('Internal error occurred, please contact your PlanQK administrator');
}
}
async runJob(payload) {
var _a, _b;
var _a;
const organizationId = ((_a = this.userConfig.context) === null || _a === void 0 ? void 0 : _a.isOrganization) ? this.userConfig.context.id : undefined;
try {
const response = await this.jobApi.createJob(payload, organizationId, { headers: { 'X-Auth-Token': this.userConfig.auth.value } });
return response.body;
return await this.jobApi.createJob({ createJobRequest: payload, xOrganizationId: organizationId });
}
catch (error) {
if (error instanceof apis_1.HttpError) {
if (error.statusCode === 404) {
this.cmd.error(`Service you want to execute was not found in context ${(_b = this.userConfig.context) === null || _b === void 0 ? void 0 : _b.displayName}. Are you in the correct context?`);
}
const errorMessage = this.getErrorMessage(error);
this.cmd.error(`Error creating job: ${errorMessage}`);
}
catch {
throw new Error('Internal error occurred, please contact your PlanQK administrator');

@@ -137,12 +132,17 @@ }

const organizationId = ((_a = this.userConfig.context) === null || _a === void 0 ? void 0 : _a.isOrganization) ? this.userConfig.context.id : undefined;
const response = await this.jobApi.getJob(id, organizationId, { headers: { 'X-Auth-Token': this.userConfig.auth.value } });
return response.body;
try {
return await this.jobApi.getJob({ id, xOrganizationId: organizationId });
}
catch {
throw new Error('Internal error occurred, please contact your PlanQK administrator');
}
}
async getAccounts() {
var _a, _b;
var _a;
try {
const basePath = ((_a = this.userConfig.endpoint) === null || _a === void 0 ? void 0 : _a.basePath) || user_config_1.defaultBasePath;
const payload = await axios_1.default
.get(basePath + '/my/accounts', { headers: { 'X-Auth-Token': (_b = this.userConfig.auth) === null || _b === void 0 ? void 0 : _b.value } });
return payload.data;
const payload = await fetch(basePath + '/my/accounts', {
headers: { 'X-Auth-Token': this.userConfig.auth.value },
});
return (await payload.json());
}

@@ -153,7 +153,3 @@ catch {

}
getErrorMessage(error) {
const errorMessage = error.body && error.body.errorMessage ? error.body.errorMessage : error.message;
return `${errorMessage} (${error.response.statusCode} - ${error.response.statusMessage})`;
}
}
exports.default = PlanqkService;
{
"version": "1.10.1",
"version": "1.11.0-alpha.1",
"commands": {

@@ -4,0 +4,0 @@ "get-context": {

{
"name": "@anaqor/planqk",
"version": "1.10.1",
"version": "1.11.0-alpha.1",
"description": "PlanQK Platform CLI",

@@ -35,8 +35,5 @@ "author": "Anaqor AG",

"async-wait-until": "^2.0.12",
"axios": "^1.4.0",
"fs-extra": "^11.1.1",
"inquirer": "^8.0.0",
"js-yaml": "^4.1.0",
"mime-types": "^2.1.35",
"request": "2.88.2"
"js-yaml": "^4.1.0"
},

@@ -50,6 +47,4 @@ "devDependencies": {

"@types/js-yaml": "^4.0.5",
"@types/mime-types": "^2.1.1",
"@types/mocha": "^10.0.1",
"@types/node": "^18.16.3",
"@types/request": "2.48.8",
"chai": "^4.3.7",

@@ -56,0 +51,0 @@ "eslint": "^7.32.0",

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