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

@contember/client

Package Overview
Dependencies
Maintainers
5
Versions
204
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contember/client - npm Package Compare versions

Comparing version 1.2.6 to 1.3.0-alpha.2

dist/development/content/formatContentApiRelativeUrl.cjs

67

dist/development/content/upload/GenerateUploadUrlMutationBuilder.js

@@ -7,27 +7,56 @@ var __defProp = Object.defineProperty;

};
import { ObjectBuilder } from "../../graphQlBuilder/ObjectBuilder.js";
import { QueryBuilder } from "../../graphQlBuilder/QueryBuilder.js";
import { GraphQlField, GraphQlQueryPrinter } from "@contember/graphql-builder";
import { GraphQlBuilder } from "../../index.js";
import { replaceGraphQlLiteral } from "../replaceGraphQlLiteral.js";
const _GenerateUploadUrlMutationBuilder = class {
/**
* @internal
*/
static buildQuery(parameters) {
return new QueryBuilder().mutation((builder) => {
for (const alias in parameters) {
const fileParameters = parameters[alias];
if (fileParameters.suffix || fileParameters.fileName || fileParameters.extension) {
builder = builder.object(
alias,
_GenerateUploadUrlMutationBuilder.generateUploadUrlFields.argument("input", fileParameters)
);
} else {
builder = builder.object(
alias,
_GenerateUploadUrlMutationBuilder.generateUploadUrlFields.argument("contentType", fileParameters.contentType).argument("expiration", fileParameters.expiration).argument("prefix", fileParameters.prefix).argument("acl", fileParameters.acl)
);
}
const selectionItems = [];
for (const alias in parameters) {
const fileParameters = parameters[alias];
if (fileParameters.suffix || fileParameters.fileName || fileParameters.extension) {
const value = replaceGraphQlLiteral(fileParameters);
selectionItems.push(new GraphQlField(alias, "generateUploadUrl", {
input: {
value,
graphQlType: "S3GenerateSignedUploadInput"
}
}, _GenerateUploadUrlMutationBuilder.generateUploadUrlFields));
} else {
selectionItems.push(new GraphQlField(alias, "generateUploadUrl", {
contentType: {
graphQlType: "String",
value: fileParameters.contentType
},
expiration: {
graphQlType: "Int",
value: fileParameters.expiration
},
prefix: {
graphQlType: "String",
value: fileParameters.prefix
},
acl: {
graphQlType: "S3Acl",
value: fileParameters.acl instanceof GraphQlBuilder.GraphqlLiteral ? fileParameters.acl?.value : fileParameters.acl
}
}, _GenerateUploadUrlMutationBuilder.generateUploadUrlFields));
}
return builder;
});
}
const printer = new GraphQlQueryPrinter();
return printer.printDocument("mutation", selectionItems, {});
}
};
let GenerateUploadUrlMutationBuilder = _GenerateUploadUrlMutationBuilder;
__publicField(GenerateUploadUrlMutationBuilder, "generateUploadUrlFields", new ObjectBuilder().name("generateUploadUrl").field("url").field("publicUrl").field("method").object("headers", (builder) => builder.field("key").field("value")));
__publicField(GenerateUploadUrlMutationBuilder, "generateUploadUrlFields", [
new GraphQlField(null, "url"),
new GraphQlField(null, "publicUrl"),
new GraphQlField(null, "method"),
new GraphQlField(null, "headers", {}, [
new GraphQlField(null, "key"),
new GraphQlField(null, "value")
])
]);
export {

@@ -34,0 +63,0 @@ GenerateUploadUrlMutationBuilder

@@ -52,4 +52,3 @@ var __defProp = Object.defineProperty;

try {
const response = await options.contentApiClient.sendRequest(mutation);
const responseData = response.data;
const responseData = await options.contentApiClient.execute(mutation.query, { variables: mutation.variables });
const limit = pLimit(this.options.concurrency ?? 5);

@@ -56,0 +55,0 @@ const promises = [];

class GraphQlLiteral {
constructor(value) {
this.value = value;
{
console.warn("GraphQlLiteral is deprecated, use the value directly instead.");
}
}

@@ -5,0 +8,0 @@ toString() {

@@ -1,18 +0,11 @@

class GraphQlClient {
constructor(apiUrl, apiToken) {
this.apiUrl = apiUrl;
this.apiToken = apiToken;
}
async sendRequest(query, { apiTokenOverride, signal, variables, headers } = {}) {
const resolvedHeaders = { "Content-Type": "application/json", ...headers };
const resolvedToken = apiTokenOverride ?? this.apiToken;
if (resolvedToken !== void 0) {
resolvedHeaders["Authorization"] = `Bearer ${resolvedToken}`;
}
import { GraphQlClient as GraphQlClient$1 } from "@contember/graphql-client";
class GraphQlClient extends GraphQlClient$1 {
/**
* @deprecated use execute
*/
async sendRequest(query, options = {}) {
console.debug(query);
const response = await fetch(this.apiUrl, {
method: "POST",
headers: resolvedHeaders,
signal,
body: JSON.stringify({ query, variables })
const response = await this.doExecute(query, {
...options,
apiToken: options.apiTokenOverride ?? options.apiToken
});

@@ -19,0 +12,0 @@ if (response.ok) {

@@ -0,13 +1,3 @@

export * from "@contember/client-content";
import { GraphQlLiteral } from "./graphQlBuilder/GraphQlLiteral.js";
import { ObjectBuilder } from "./graphQlBuilder/ObjectBuilder.js";
import { QueryCompiler } from "./graphQlBuilder/QueryCompiler.js";
import { QueryBuilder } from "./graphQlBuilder/QueryBuilder.js";
import { RootObjectBuilder } from "./graphQlBuilder/RootObjectBuilder.js";
import { CrudQueryBuilder as CrudQueryBuilder$1 } from "./crudQueryBuilder/CrudQueryBuilder.js";
import { ReadBuilder } from "./crudQueryBuilder/ReadBuilder.js";
import { WriteBuilder } from "./crudQueryBuilder/WriteBuilder.js";
import { WriteDataBuilder } from "./crudQueryBuilder/WriteDataBuilder.js";
import { WriteManyRelationBuilder } from "./crudQueryBuilder/WriteManyRelationBuilder.js";
import { WriteOneRelationBuilder } from "./crudQueryBuilder/WriteOneRelationBuilder.js";
import { WriteOperation } from "./crudQueryBuilder/types.js";
import { FileUploadError } from "./content/upload/FileUploadError.js";

@@ -18,2 +8,4 @@ import { GenerateUploadUrlMutationBuilder } from "./content/upload/GenerateUploadUrlMutationBuilder.js";

import { formatContentApiRelativeUrl } from "./content/formatContentApiRelativeUrl.js";
import { replaceGraphQlLiteral } from "./content/replaceGraphQlLiteral.js";
import { GraphQlClientError } from "@contember/graphql-client";
import { GraphQlClient } from "./graphQlClient/GraphQlClient.js";

@@ -28,19 +20,4 @@ import { formatSystemApiRelativeUrl } from "./system/formatSystemApiRelativeUrl.js";

GraphQlBuilder2.GraphQlLiteral = GraphQlLiteral;
GraphQlBuilder2.ObjectBuilder = ObjectBuilder;
GraphQlBuilder2.QueryCompiler = QueryCompiler;
GraphQlBuilder2.QueryBuilder = QueryBuilder;
GraphQlBuilder2.RootObjectBuilder = RootObjectBuilder;
})(GraphQlBuilder || (GraphQlBuilder = {}));
var CrudQueryBuilder;
((_CrudQueryBuilder) => {
_CrudQueryBuilder.CrudQueryBuilder = CrudQueryBuilder$1;
_CrudQueryBuilder.ReadBuilder = ReadBuilder;
_CrudQueryBuilder.WriteBuilder = WriteBuilder;
_CrudQueryBuilder.WriteDataBuilder = WriteDataBuilder;
_CrudQueryBuilder.WriteManyRelationBuilder = WriteManyRelationBuilder;
_CrudQueryBuilder.WriteOneRelationBuilder = WriteOneRelationBuilder;
_CrudQueryBuilder.WriteOperation = WriteOperation;
})(CrudQueryBuilder || (CrudQueryBuilder = {}));
export {
CrudQueryBuilder,
FileUploadError,

@@ -50,2 +27,3 @@ GenerateUploadUrlMutationBuilder,

GraphQlClient,
GraphQlClientError,
GraphQlLiteral,

@@ -57,2 +35,3 @@ S3FileUploader,

loginMutation,
replaceGraphQlLiteral,
tenantApiRelativeUrl,

@@ -59,0 +38,0 @@ tenantErrorMessages,

@@ -7,27 +7,56 @@ var __defProp = Object.defineProperty;

};
import { ObjectBuilder } from "../../graphQlBuilder/ObjectBuilder.js";
import { QueryBuilder } from "../../graphQlBuilder/QueryBuilder.js";
import { GraphQlField, GraphQlQueryPrinter } from "@contember/graphql-builder";
import { GraphQlBuilder } from "../../index.js";
import { replaceGraphQlLiteral } from "../replaceGraphQlLiteral.js";
const _GenerateUploadUrlMutationBuilder = class {
/**
* @internal
*/
static buildQuery(parameters) {
return new QueryBuilder().mutation((builder) => {
for (const alias in parameters) {
const fileParameters = parameters[alias];
if (fileParameters.suffix || fileParameters.fileName || fileParameters.extension) {
builder = builder.object(
alias,
_GenerateUploadUrlMutationBuilder.generateUploadUrlFields.argument("input", fileParameters)
);
} else {
builder = builder.object(
alias,
_GenerateUploadUrlMutationBuilder.generateUploadUrlFields.argument("contentType", fileParameters.contentType).argument("expiration", fileParameters.expiration).argument("prefix", fileParameters.prefix).argument("acl", fileParameters.acl)
);
}
const selectionItems = [];
for (const alias in parameters) {
const fileParameters = parameters[alias];
if (fileParameters.suffix || fileParameters.fileName || fileParameters.extension) {
const value = replaceGraphQlLiteral(fileParameters);
selectionItems.push(new GraphQlField(alias, "generateUploadUrl", {
input: {
value,
graphQlType: "S3GenerateSignedUploadInput"
}
}, _GenerateUploadUrlMutationBuilder.generateUploadUrlFields));
} else {
selectionItems.push(new GraphQlField(alias, "generateUploadUrl", {
contentType: {
graphQlType: "String",
value: fileParameters.contentType
},
expiration: {
graphQlType: "Int",
value: fileParameters.expiration
},
prefix: {
graphQlType: "String",
value: fileParameters.prefix
},
acl: {
graphQlType: "S3Acl",
value: fileParameters.acl instanceof GraphQlBuilder.GraphqlLiteral ? fileParameters.acl?.value : fileParameters.acl
}
}, _GenerateUploadUrlMutationBuilder.generateUploadUrlFields));
}
return builder;
});
}
const printer = new GraphQlQueryPrinter();
return printer.printDocument("mutation", selectionItems, {});
}
};
let GenerateUploadUrlMutationBuilder = _GenerateUploadUrlMutationBuilder;
__publicField(GenerateUploadUrlMutationBuilder, "generateUploadUrlFields", new ObjectBuilder().name("generateUploadUrl").field("url").field("publicUrl").field("method").object("headers", (builder) => builder.field("key").field("value")));
__publicField(GenerateUploadUrlMutationBuilder, "generateUploadUrlFields", [
new GraphQlField(null, "url"),
new GraphQlField(null, "publicUrl"),
new GraphQlField(null, "method"),
new GraphQlField(null, "headers", {}, [
new GraphQlField(null, "key"),
new GraphQlField(null, "value")
])
]);
export {

@@ -34,0 +63,0 @@ GenerateUploadUrlMutationBuilder

@@ -52,4 +52,3 @@ var __defProp = Object.defineProperty;

try {
const response = await options.contentApiClient.sendRequest(mutation);
const responseData = response.data;
const responseData = await options.contentApiClient.execute(mutation.query, { variables: mutation.variables });
const limit = pLimit(this.options.concurrency ?? 5);

@@ -56,0 +55,0 @@ const promises = [];

@@ -1,18 +0,11 @@

class GraphQlClient {
constructor(apiUrl, apiToken) {
this.apiUrl = apiUrl;
this.apiToken = apiToken;
}
async sendRequest(query, { apiTokenOverride, signal, variables, headers } = {}) {
const resolvedHeaders = { "Content-Type": "application/json", ...headers };
const resolvedToken = apiTokenOverride ?? this.apiToken;
if (resolvedToken !== void 0) {
resolvedHeaders["Authorization"] = `Bearer ${resolvedToken}`;
}
import { GraphQlClient as GraphQlClient$1 } from "@contember/graphql-client";
class GraphQlClient extends GraphQlClient$1 {
/**
* @deprecated use execute
*/
async sendRequest(query, options = {}) {
console.debug(query);
const response = await fetch(this.apiUrl, {
method: "POST",
headers: resolvedHeaders,
signal,
body: JSON.stringify({ query, variables })
const response = await this.doExecute(query, {
...options,
apiToken: options.apiTokenOverride ?? options.apiToken
});

@@ -19,0 +12,0 @@ if (response.ok) {

@@ -0,13 +1,3 @@

export * from "@contember/client-content";
import { GraphQlLiteral } from "./graphQlBuilder/GraphQlLiteral.js";
import { ObjectBuilder } from "./graphQlBuilder/ObjectBuilder.js";
import { QueryCompiler } from "./graphQlBuilder/QueryCompiler.js";
import { QueryBuilder } from "./graphQlBuilder/QueryBuilder.js";
import { RootObjectBuilder } from "./graphQlBuilder/RootObjectBuilder.js";
import { CrudQueryBuilder as CrudQueryBuilder$1 } from "./crudQueryBuilder/CrudQueryBuilder.js";
import { ReadBuilder } from "./crudQueryBuilder/ReadBuilder.js";
import { WriteBuilder } from "./crudQueryBuilder/WriteBuilder.js";
import { WriteDataBuilder } from "./crudQueryBuilder/WriteDataBuilder.js";
import { WriteManyRelationBuilder } from "./crudQueryBuilder/WriteManyRelationBuilder.js";
import { WriteOneRelationBuilder } from "./crudQueryBuilder/WriteOneRelationBuilder.js";
import { WriteOperation } from "./crudQueryBuilder/types.js";
import { FileUploadError } from "./content/upload/FileUploadError.js";

@@ -18,2 +8,4 @@ import { GenerateUploadUrlMutationBuilder } from "./content/upload/GenerateUploadUrlMutationBuilder.js";

import { formatContentApiRelativeUrl } from "./content/formatContentApiRelativeUrl.js";
import { replaceGraphQlLiteral } from "./content/replaceGraphQlLiteral.js";
import { GraphQlClientError } from "@contember/graphql-client";
import { GraphQlClient } from "./graphQlClient/GraphQlClient.js";

@@ -28,19 +20,4 @@ import { formatSystemApiRelativeUrl } from "./system/formatSystemApiRelativeUrl.js";

GraphQlBuilder2.GraphQlLiteral = GraphQlLiteral;
GraphQlBuilder2.ObjectBuilder = ObjectBuilder;
GraphQlBuilder2.QueryCompiler = QueryCompiler;
GraphQlBuilder2.QueryBuilder = QueryBuilder;
GraphQlBuilder2.RootObjectBuilder = RootObjectBuilder;
})(GraphQlBuilder || (GraphQlBuilder = {}));
var CrudQueryBuilder;
((_CrudQueryBuilder) => {
_CrudQueryBuilder.CrudQueryBuilder = CrudQueryBuilder$1;
_CrudQueryBuilder.ReadBuilder = ReadBuilder;
_CrudQueryBuilder.WriteBuilder = WriteBuilder;
_CrudQueryBuilder.WriteDataBuilder = WriteDataBuilder;
_CrudQueryBuilder.WriteManyRelationBuilder = WriteManyRelationBuilder;
_CrudQueryBuilder.WriteOneRelationBuilder = WriteOneRelationBuilder;
_CrudQueryBuilder.WriteOperation = WriteOperation;
})(CrudQueryBuilder || (CrudQueryBuilder = {}));
export {
CrudQueryBuilder,
FileUploadError,

@@ -50,2 +27,3 @@ GenerateUploadUrlMutationBuilder,

GraphQlClient,
GraphQlClientError,
GraphQlLiteral,

@@ -57,2 +35,3 @@ S3FileUploader,

loginMutation,
replaceGraphQlLiteral,
tenantApiRelativeUrl,

@@ -59,0 +38,0 @@ tenantErrorMessages,

export * from './upload';
export * from './params';
export * from './formatContentApiRelativeUrl';
export * from './replaceGraphQlLiteral';
//# sourceMappingURL=index.d.ts.map
import { GraphQlLiteral } from '../../graphQlBuilder';
import { GraphQlPrintResult } from '@contember/graphql-builder';
declare class GenerateUploadUrlMutationBuilder {
private static generateUploadUrlFields;
static buildQuery(parameters: GenerateUploadUrlMutationBuilder.MutationParameters): string;
/**
* @internal
*/
static buildQuery(parameters: GenerateUploadUrlMutationBuilder.MutationParameters): GraphQlPrintResult;
}
declare namespace GenerateUploadUrlMutationBuilder {
type Acl = GraphQlLiteral<'PUBLIC_READ' | 'PRIVATE' | 'NONE'>;
interface FileParameters {
type Acl = 'PUBLIC_READ' | 'PRIVATE' | 'NONE' | GraphQlLiteral<'PUBLIC_READ' | 'PRIVATE' | 'NONE'>;
type FileParameters = {
contentType: string;

@@ -17,3 +21,3 @@ expiration?: number;

acl?: Acl;
}
};
interface MutationParameters {

@@ -20,0 +24,0 @@ [alias: string]: FileParameters;

@@ -1,8 +0,2 @@

export * from './CrudQueryBuilder';
export * from './ReadBuilder';
export * from './types';
export * from './WriteBuilder';
export * from './WriteDataBuilder';
export * from './WriteManyRelationBuilder';
export * from './WriteOneRelationBuilder';
//# sourceMappingURL=index.d.ts.map

@@ -0,45 +1,4 @@

import { Input } from '@contember/schema';
import { GraphQlLiteral } from '../graphQlBuilder';
export type Mutations = 'create' | 'update' | 'delete';
export type Queries = 'get' | 'list' | 'paginate';
export type GetQueryArguments = 'by' | 'filter';
export type ListQueryArguments = 'filter' | 'orderBy' | 'offset' | 'limit';
export type PaginateQueryArguments = 'filter' | 'orderBy' | 'skip' | 'first';
export type CreateMutationArguments = 'data';
export type UpdateMutationArguments = 'data' | 'by';
export type DeleteMutationArguments = 'by';
export type ReductionArguments = 'filter' | 'by';
export type HasOneArguments = 'filter';
export type HasManyArguments = 'filter' | 'orderBy' | 'offset' | 'limit';
export type UpdateMutationFields = 'ok' | 'validation' | 'errors' | 'errorMessage' | 'node';
export type CreateMutationFields = 'ok' | 'validation' | 'errors' | 'errorMessage' | 'node';
export type DeleteMutationFields = 'ok' | 'node' | 'errors' | 'errorMessage';
export type WriteArguments = CreateMutationArguments | UpdateMutationArguments | DeleteMutationArguments;
export type WriteFields = UpdateMutationFields | CreateMutationFields;
export type ReadArguments = GetQueryArguments | ListQueryArguments | PaginateQueryArguments | HasOneArguments | HasManyArguments;
export interface WriteRelationOps {
create: 'create' | 'connect';
update: 'create' | 'connect' | 'delete' | 'disconnect' | 'update' | 'upsert';
}
export type OrderDirection = GraphQlLiteral<'asc'> | GraphQlLiteral<'desc'>;
export declare namespace WriteOperation {
interface Operation {
op: 'create' | 'update' | 'delete';
}
abstract class Operation implements Operation {
}
interface ContentfulOperation {
op: 'create' | 'update';
}
abstract class ContentfulOperation extends Operation implements ContentfulOperation {
}
class Update extends ContentfulOperation {
readonly op: "update";
}
class Create extends ContentfulOperation {
readonly op: "create";
}
class Delete extends Operation {
readonly op: "delete";
}
}
export type OrderDirection = GraphQlLiteral<'asc'> | GraphQlLiteral<'desc'> | `${Input.OrderDirection}`;
//# sourceMappingURL=types.d.ts.map

@@ -0,1 +1,4 @@

/**
* @deprecated Directly use the value instead.
*/
export declare class GraphQlLiteral<Value extends string = string> {

@@ -2,0 +5,0 @@ readonly value: Value;

export * from './GraphQlLiteral';
export * from './ObjectBuilder';
export * from './QueryBuilder';
export * from './QueryCompiler';
export * from './RootObjectBuilder';
//# sourceMappingURL=index.d.ts.map
import type { GraphQlLiteral } from './GraphQlLiteral';
import { RootObjectBuilder } from './RootObjectBuilder';
declare class QueryBuilder {
query(builder: ((builder: RootObjectBuilder) => RootObjectBuilder) | RootObjectBuilder): string;
mutation(builder: ((builder: RootObjectBuilder) => RootObjectBuilder) | RootObjectBuilder): string;
}
declare namespace QueryBuilder {
export declare namespace QueryBuilder {
interface Object {

@@ -14,5 +9,4 @@ [key: string]: Value;

type AtomicValue = string | null | number | boolean | GraphQlLiteral;
type Value = AtomicValue | QueryBuilder.Object | List;
type Value = AtomicValue | Object | List;
}
export { QueryBuilder };
//# sourceMappingURL=QueryBuilder.d.ts.map

@@ -1,19 +0,17 @@

export interface GraphQlClientRequestOptions {
variables?: GraphQlClientVariables;
import { GraphQlClient as BaseGraphQLClient, GraphQlClientRequestOptions as BaseGraphQlClientRequestOptions } from '@contember/graphql-client';
export interface GraphQlClientRequestOptions extends BaseGraphQlClientRequestOptions {
/**
* @deprecated use apiToken
*/
apiTokenOverride?: string;
signal?: AbortSignal;
headers?: Record<string, string>;
}
export interface GraphQlClientVariables {
[name: string]: any;
}
export type GraphQlClientFailedRequestMetadata = Pick<Response, 'status' | 'statusText'> & {
responseText: string;
};
export declare class GraphQlClient {
readonly apiUrl: string;
private readonly apiToken?;
constructor(apiUrl: string, apiToken?: string | undefined);
sendRequest<T = unknown>(query: string, { apiTokenOverride, signal, variables, headers }?: GraphQlClientRequestOptions): Promise<T>;
export declare class GraphQlClient extends BaseGraphQLClient {
/**
* @deprecated use execute
*/
sendRequest<T = unknown>(query: string, options?: GraphQlClientRequestOptions): Promise<T>;
}
//# sourceMappingURL=GraphQlClient.d.ts.map
export * from './GraphQlClient';
export type { GraphQlClientVariables, GraphQlErrorType, GraphQlErrorRequest, } from '@contember/graphql-client';
export { GraphQlClientError } from '@contember/graphql-client';
//# sourceMappingURL=index.d.ts.map

@@ -7,34 +7,5 @@ import * as CrudQueryBuilderTmp from './crudQueryBuilder';

export import GraphQlLiteral = GraphQlBuilderTmp.GraphQlLiteral;
export import ObjectBuilder = GraphQlBuilderTmp.ObjectBuilder;
export import QueryCompiler = GraphQlBuilderTmp.QueryCompiler;
export import QueryBuilder = GraphQlBuilderTmp.QueryBuilder;
export import RootObjectBuilder = GraphQlBuilderTmp.RootObjectBuilder;
}
export declare namespace CrudQueryBuilder {
export import CrudQueryBuilder = CrudQueryBuilderTmp.CrudQueryBuilder;
export import ReadBuilder = CrudQueryBuilderTmp.ReadBuilder;
export import WriteBuilder = CrudQueryBuilderTmp.WriteBuilder;
export import WriteDataBuilder = CrudQueryBuilderTmp.WriteDataBuilder;
export import WriteManyRelationBuilder = CrudQueryBuilderTmp.WriteManyRelationBuilder;
export import WriteOneRelationBuilder = CrudQueryBuilderTmp.WriteOneRelationBuilder;
export import WriteOperation = CrudQueryBuilderTmp.WriteOperation;
type CreateMutationArguments = CrudQueryBuilderTmp.CreateMutationArguments;
type CreateMutationFields = CrudQueryBuilderTmp.CreateMutationFields;
type DeleteMutationArguments = CrudQueryBuilderTmp.DeleteMutationArguments;
type DeleteMutationFields = CrudQueryBuilderTmp.DeleteMutationFields;
type GetQueryArguments = CrudQueryBuilderTmp.GetQueryArguments;
type HasManyArguments = CrudQueryBuilderTmp.HasManyArguments;
type HasOneArguments = CrudQueryBuilderTmp.HasOneArguments;
type ListQueryArguments = CrudQueryBuilderTmp.ListQueryArguments;
type Mutations = CrudQueryBuilderTmp.Mutations;
type OrderDirection = CrudQueryBuilderTmp.OrderDirection;
type PaginateQueryArguments = CrudQueryBuilderTmp.PaginateQueryArguments;
type Queries = CrudQueryBuilderTmp.Queries;
type ReadArguments = CrudQueryBuilderTmp.ReadArguments;
type ReductionArguments = CrudQueryBuilderTmp.ReductionArguments;
type UpdateMutationArguments = CrudQueryBuilderTmp.UpdateMutationArguments;
type UpdateMutationFields = CrudQueryBuilderTmp.UpdateMutationFields;
type WriteArguments = CrudQueryBuilderTmp.WriteArguments;
type WriteFields = CrudQueryBuilderTmp.WriteFields;
type WriteRelationOps = CrudQueryBuilderTmp.WriteRelationOps;
}

@@ -45,3 +16,4 @@ export * from './content';

export * from './tenant';
export * from '@contember/client-content';
export type { Input, Value, Result, Writable } from '@contember/schema';
//# sourceMappingURL=index.d.ts.map
{
"name": "@contember/client",
"license": "Apache-2.0",
"version": "1.2.6",
"version": "1.3.0-alpha.2",
"main": "./dist/production/index.js",

@@ -13,2 +13,8 @@ "exports": {

"default": "./dist/production/index.js"
},
"require": {
"types": "./dist/types/index.d.ts",
"development": "./dist/development/index.cjs",
"production": "./dist/production/index.cjs",
"default": "./dist/production/index.cjs"
}

@@ -33,5 +39,14 @@ }

"dependencies": {
"@contember/schema": "^1.2.0",
"@contember/client-content": "1.3.0-alpha.2",
"@contember/graphql-builder": "1.3.0-alpha.2",
"@contember/graphql-client": "1.3.0-alpha.2",
"@contember/schema": "^1.3.6",
"p-limit": "^4.0.0"
}
},
"repository": {
"type": "git",
"url": "https://github.com/contember/interface.git",
"directory": "packages/client"
},
"stableVersion": "0.0.0"
}
export * from './upload'
export * from './params'
export * from './formatContentApiRelativeUrl'
export * from './replaceGraphQlLiteral'

@@ -1,36 +0,55 @@

import { GraphQlLiteral, ObjectBuilder, QueryBuilder } from '../../graphQlBuilder'
import { GraphQlLiteral } from '../../graphQlBuilder'
import { GraphQlField, GraphQlPrintResult, GraphQlQueryPrinter, GraphQlSelectionSetItem } from '@contember/graphql-builder'
import { GraphQlBuilder } from '../../index'
import { replaceGraphQlLiteral } from '../replaceGraphQlLiteral'
class GenerateUploadUrlMutationBuilder {
private static generateUploadUrlFields = new ObjectBuilder()
.name('generateUploadUrl')
.field('url')
.field('publicUrl')
.field('method')
.object('headers', builder => builder.field('key').field('value'))
public static buildQuery(parameters: GenerateUploadUrlMutationBuilder.MutationParameters): string {
return new QueryBuilder().mutation(builder => {
for (const alias in parameters) {
const fileParameters = parameters[alias]
if (fileParameters.suffix || fileParameters.fileName || fileParameters.extension) {
builder = builder.object(
alias,
GenerateUploadUrlMutationBuilder.generateUploadUrlFields
.argument('input', fileParameters),
)
} else {
// BC
builder = builder.object(
alias,
GenerateUploadUrlMutationBuilder.generateUploadUrlFields
.argument('contentType', fileParameters.contentType)
.argument('expiration', fileParameters.expiration)
.argument('prefix', fileParameters.prefix)
.argument('acl', fileParameters.acl),
)
}
private static generateUploadUrlFields = [
new GraphQlField(null, 'url'),
new GraphQlField(null, 'publicUrl'),
new GraphQlField(null, 'method'),
new GraphQlField(null, 'headers', {}, [
new GraphQlField(null, 'key'),
new GraphQlField(null, 'value'),
]),
]
/**
* @internal
*/
public static buildQuery(parameters: GenerateUploadUrlMutationBuilder.MutationParameters): GraphQlPrintResult {
const selectionItems: GraphQlSelectionSetItem[] = []
for (const alias in parameters) {
const fileParameters = parameters[alias]
if (fileParameters.suffix || fileParameters.fileName || fileParameters.extension) {
const value = replaceGraphQlLiteral(fileParameters)
selectionItems.push(new GraphQlField(alias, 'generateUploadUrl', {
input: {
value: value,
graphQlType: 'S3GenerateSignedUploadInput',
},
}, GenerateUploadUrlMutationBuilder.generateUploadUrlFields))
} else {
selectionItems.push(new GraphQlField(alias, 'generateUploadUrl', {
contentType: {
graphQlType: 'String',
value: fileParameters.contentType,
},
expiration: {
graphQlType: 'Int',
value: fileParameters.expiration,
},
prefix: {
graphQlType: 'String',
value: fileParameters.prefix,
},
acl: {
graphQlType: 'S3Acl',
value: fileParameters.acl instanceof GraphQlBuilder.GraphqlLiteral ? fileParameters.acl?.value : fileParameters.acl,
},
}, GenerateUploadUrlMutationBuilder.generateUploadUrlFields))
}
}
return builder
})
const printer = new GraphQlQueryPrinter()
return printer.printDocument('mutation', selectionItems, {})
}

@@ -40,5 +59,9 @@ }

namespace GenerateUploadUrlMutationBuilder {
export type Acl = GraphQlLiteral<'PUBLIC_READ' | 'PRIVATE' | 'NONE'>;
export type Acl =
| 'PUBLIC_READ'
| 'PRIVATE'
| 'NONE'
| GraphQlLiteral<'PUBLIC_READ' | 'PRIVATE' | 'NONE'>
export interface FileParameters {
export type FileParameters = {
contentType: string

@@ -45,0 +68,0 @@ expiration?: number

@@ -66,4 +66,3 @@ import pLimit from 'p-limit'

try {
const response = await options.contentApiClient.sendRequest<{ data: GenerateUploadUrlMutationBuilder.MutationResponse }>(mutation)
const responseData = response.data
const responseData = await options.contentApiClient.execute<GenerateUploadUrlMutationBuilder.MutationResponse>(mutation.query, { variables: mutation.variables })
const limit = pLimit(this.options.concurrency ?? 5)

@@ -70,0 +69,0 @@ const promises: Promise<void>[] = []

@@ -1,7 +0,1 @@

export * from './CrudQueryBuilder'
export * from './ReadBuilder'
export * from './types'
export * from './WriteBuilder'
export * from './WriteDataBuilder'
export * from './WriteManyRelationBuilder'
export * from './WriteOneRelationBuilder'

@@ -0,73 +1,8 @@

import { Input } from '@contember/schema'
import { GraphQlLiteral } from '../graphQlBuilder'
export type Mutations = 'create' | 'update' | 'delete'
export type OrderDirection =
| GraphQlLiteral<'asc'>
| GraphQlLiteral<'desc'>
| `${Input.OrderDirection}`
export type Queries = 'get' | 'list' | 'paginate'
export type GetQueryArguments = 'by' | 'filter'
export type ListQueryArguments = 'filter' | 'orderBy' | 'offset' | 'limit'
export type PaginateQueryArguments = 'filter' | 'orderBy' | 'skip' | 'first'
export type CreateMutationArguments = 'data'
export type UpdateMutationArguments = 'data' | 'by'
export type DeleteMutationArguments = 'by'
export type ReductionArguments = 'filter' | 'by'
export type HasOneArguments = 'filter'
export type HasManyArguments = 'filter' | 'orderBy' | 'offset' | 'limit'
export type UpdateMutationFields = 'ok' | 'validation' | 'errors' | 'errorMessage' | 'node'
export type CreateMutationFields = 'ok' | 'validation' | 'errors' | 'errorMessage' | 'node'
export type DeleteMutationFields = 'ok' | 'node' | 'errors' | 'errorMessage'
export type WriteArguments = CreateMutationArguments | UpdateMutationArguments | DeleteMutationArguments
export type WriteFields = UpdateMutationFields | CreateMutationFields
export type ReadArguments =
| GetQueryArguments
| ListQueryArguments
| PaginateQueryArguments
| HasOneArguments
| HasManyArguments
export interface WriteRelationOps {
create: 'create' | 'connect'
update: 'create' | 'connect' | 'delete' | 'disconnect' | 'update' | 'upsert'
}
export type OrderDirection = GraphQlLiteral<'asc'> | GraphQlLiteral<'desc'>
// TODO Silly enums because TS does not support enum extension 🙄
// https://github.com/Microsoft/TypeScript/issues/17592
export namespace WriteOperation {
export interface Operation {
op: 'create' | 'update' | 'delete'
}
export abstract class Operation implements Operation {}
export interface ContentfulOperation {
op: 'create' | 'update'
}
export abstract class ContentfulOperation extends Operation implements ContentfulOperation {}
export class Update extends ContentfulOperation {
override readonly op = 'update' as const
}
export class Create extends ContentfulOperation {
override readonly op = 'create' as const
}
export class Delete extends Operation {
override readonly op = 'delete' as const
}
}

@@ -0,3 +1,10 @@

/**
* @deprecated Directly use the value instead.
*/
export class GraphQlLiteral<Value extends string = string> {
constructor(public readonly value: Value) {}
constructor(public readonly value: Value) {
if (import.meta.env.DEV) {
console.warn('GraphQlLiteral is deprecated, use the value directly instead.')
}
}

@@ -4,0 +11,0 @@ public toString() {

export * from './GraphQlLiteral'
export * from './ObjectBuilder'
export * from './QueryBuilder'
export * from './QueryCompiler'
export * from './RootObjectBuilder'
import type { GraphQlLiteral } from './GraphQlLiteral'
import { QueryCompiler } from './QueryCompiler'
import { RootObjectBuilder } from './RootObjectBuilder'
class QueryBuilder {
query(builder: ((builder: RootObjectBuilder) => RootObjectBuilder) | RootObjectBuilder): string {
if (!(builder instanceof RootObjectBuilder)) {
builder = builder(new RootObjectBuilder())
}
const compiler = new QueryCompiler('query', builder)
return compiler.create()
}
mutation(builder: ((builder: RootObjectBuilder) => RootObjectBuilder) | RootObjectBuilder): string {
if (!(builder instanceof RootObjectBuilder)) {
builder = builder(new RootObjectBuilder())
}
const compiler = new QueryCompiler('mutation', builder)
return compiler.create()
}
}
namespace QueryBuilder {
export namespace QueryBuilder {
export interface Object {

@@ -31,5 +12,3 @@ [key: string]: Value

export type AtomicValue = string | null | number | boolean | GraphQlLiteral
export type Value = AtomicValue | QueryBuilder.Object | List
export type Value = AtomicValue | Object | List
}
export { QueryBuilder }

@@ -1,12 +0,10 @@

export interface GraphQlClientRequestOptions {
variables?: GraphQlClientVariables
import { GraphQlClient as BaseGraphQLClient, GraphQlClientRequestOptions as BaseGraphQlClientRequestOptions } from '@contember/graphql-client'
export interface GraphQlClientRequestOptions extends BaseGraphQlClientRequestOptions {
/**
* @deprecated use apiToken
*/
apiTokenOverride?: string
signal?: AbortSignal
headers?: Record<string, string>
}
export interface GraphQlClientVariables {
[name: string]: any
}
export type GraphQlClientFailedRequestMetadata = Pick<Response, 'status' | 'statusText'> & {

@@ -16,23 +14,11 @@ responseText: string

export class GraphQlClient {
constructor(public readonly apiUrl: string, private readonly apiToken?: string) { }
async sendRequest<T = unknown>(
query: string,
{ apiTokenOverride, signal, variables, headers }: GraphQlClientRequestOptions = {},
): Promise<T> {
const resolvedHeaders: Record<string, string> = { 'Content-Type': 'application/json', ...headers }
const resolvedToken = apiTokenOverride ?? this.apiToken
if (resolvedToken !== undefined) {
resolvedHeaders['Authorization'] = `Bearer ${resolvedToken}`
}
export class GraphQlClient extends BaseGraphQLClient {
/**
* @deprecated use execute
*/
async sendRequest<T = unknown>(query: string, options: GraphQlClientRequestOptions = {}): Promise<T> {
console.debug(query)
const response = await fetch(this.apiUrl, {
method: 'POST',
headers: resolvedHeaders,
signal,
body: JSON.stringify({ query, variables }),
const response = await this.doExecute(query, {
...options,
apiToken: options.apiTokenOverride ?? options.apiToken,
})

@@ -53,2 +39,3 @@

}
}
export * from './GraphQlClient'
export type {
GraphQlClientVariables,
GraphQlErrorType,
GraphQlErrorRequest,
} from '@contember/graphql-client'
export { GraphQlClientError } from '@contember/graphql-client'
import * as CrudQueryBuilderTmp from './crudQueryBuilder'
import * as GraphQlBuilderTmp from './graphQlBuilder'
export { GraphQlLiteral } from './graphQlBuilder'
export namespace GraphQlBuilder {
export import GraphqlLiteral = GraphQlBuilderTmp.GraphQlLiteral
export import GraphQlLiteral = GraphQlBuilderTmp.GraphQlLiteral
export import ObjectBuilder = GraphQlBuilderTmp.ObjectBuilder
export import QueryCompiler = GraphQlBuilderTmp.QueryCompiler
export import QueryBuilder = GraphQlBuilderTmp.QueryBuilder
export import RootObjectBuilder = GraphQlBuilderTmp.RootObjectBuilder
export import GraphqlLiteral = GraphQlBuilderTmp.GraphQlLiteral;
export import GraphQlLiteral = GraphQlBuilderTmp.GraphQlLiteral;
}
export namespace CrudQueryBuilder {
export import CrudQueryBuilder = CrudQueryBuilderTmp.CrudQueryBuilder
export import ReadBuilder = CrudQueryBuilderTmp.ReadBuilder
export import WriteBuilder = CrudQueryBuilderTmp.WriteBuilder
export import WriteDataBuilder = CrudQueryBuilderTmp.WriteDataBuilder
export import WriteManyRelationBuilder = CrudQueryBuilderTmp.WriteManyRelationBuilder
export import WriteOneRelationBuilder = CrudQueryBuilderTmp.WriteOneRelationBuilder
export import WriteOperation = CrudQueryBuilderTmp.WriteOperation
export type CreateMutationArguments = CrudQueryBuilderTmp.CreateMutationArguments
export type CreateMutationFields = CrudQueryBuilderTmp.CreateMutationFields
export type DeleteMutationArguments = CrudQueryBuilderTmp.DeleteMutationArguments
export type DeleteMutationFields = CrudQueryBuilderTmp.DeleteMutationFields
export type GetQueryArguments = CrudQueryBuilderTmp.GetQueryArguments
export type HasManyArguments = CrudQueryBuilderTmp.HasManyArguments
export type HasOneArguments = CrudQueryBuilderTmp.HasOneArguments
export type ListQueryArguments = CrudQueryBuilderTmp.ListQueryArguments
export type Mutations = CrudQueryBuilderTmp.Mutations
export type OrderDirection = CrudQueryBuilderTmp.OrderDirection
export type PaginateQueryArguments = CrudQueryBuilderTmp.PaginateQueryArguments
export type Queries = CrudQueryBuilderTmp.Queries
export type ReadArguments = CrudQueryBuilderTmp.ReadArguments
export type ReductionArguments = CrudQueryBuilderTmp.ReductionArguments
export type UpdateMutationArguments = CrudQueryBuilderTmp.UpdateMutationArguments
export type UpdateMutationFields = CrudQueryBuilderTmp.UpdateMutationFields
export type WriteArguments = CrudQueryBuilderTmp.WriteArguments
export type WriteFields = CrudQueryBuilderTmp.WriteFields
export type WriteRelationOps = CrudQueryBuilderTmp.WriteRelationOps
}

@@ -49,2 +21,4 @@

export * from '@contember/client-content'
export type { Input, Value, Result, Writable } from '@contember/schema'

@@ -5,3 +5,14 @@ {

"outDir": "../dist/types"
}
},
"references": [
{
"path": "../../client-content/src"
},
{
"path": "../../graphql-builder/src"
},
{
"path": "../../graphql-client/src"
}
]
}

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

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

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

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

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

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

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

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