@gigya/destination
Version:
Gigya API Client with SAP Cloud SDK Destination Support
1,935 lines (1,923 loc) • 72 kB
JavaScript
'use strict';
var connectivity = require('@sap-cloud-sdk/connectivity');
var httpClient = require('@sap-cloud-sdk/http-client');
const serializeFormDataPair = (data, key, value) => {
if (typeof value === "string" || value instanceof Blob) {
data.append(key, value);
} else if (value instanceof Date) {
data.append(key, value.toISOString());
} else {
data.append(key, JSON.stringify(value));
}
};
const serializeUrlSearchParamsPair = (data, key, value) => {
if (typeof value === "string") {
data.append(key, value);
} else {
data.append(key, JSON.stringify(value));
}
};
const formDataBodySerializer = {
bodySerializer: (body) => {
const data = new FormData();
Object.entries(body).forEach(([key, value]) => {
if (value === void 0 || value === null) {
return;
}
if (Array.isArray(value)) {
value.forEach((v) => serializeFormDataPair(data, key, v));
} else {
serializeFormDataPair(data, key, value);
}
});
return data;
}
};
const jsonBodySerializer = {
bodySerializer: (body) => JSON.stringify(
body,
(_key, value) => typeof value === "bigint" ? value.toString() : value
)
};
const urlSearchParamsBodySerializer = {
bodySerializer: (body) => {
const data = new URLSearchParams();
Object.entries(body).forEach(([key, value]) => {
if (value === void 0 || value === null) {
return;
}
if (Array.isArray(value)) {
value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
} else {
serializeUrlSearchParamsPair(data, key, value);
}
});
return data.toString();
}
};
const createSseClient = ({
onRequest,
onSseError,
onSseEvent,
responseTransformer,
responseValidator,
sseDefaultRetryDelay,
sseMaxRetryAttempts,
sseMaxRetryDelay,
sseSleepFn,
url,
...options
}) => {
let lastEventId;
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
const createStream = async function* () {
let retryDelay = sseDefaultRetryDelay ?? 3e3;
let attempt = 0;
const signal = options.signal ?? new AbortController().signal;
while (true) {
if (signal.aborted) break;
attempt++;
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
if (lastEventId !== void 0) {
headers.set("Last-Event-ID", lastEventId);
}
try {
const requestInit = {
redirect: "follow",
...options,
body: options.serializedBody,
headers,
signal
};
let request = new Request(url, requestInit);
if (onRequest) {
request = await onRequest(url, requestInit);
}
const _fetch = options.fetch ?? globalThis.fetch;
const response = await _fetch(request);
if (!response.ok)
throw new Error(
`SSE failed: ${response.status} ${response.statusText}`
);
if (!response.body) throw new Error("No body in SSE response");
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
let buffer = "";
const abortHandler = () => {
try {
reader.cancel();
} catch {
}
};
signal.addEventListener("abort", abortHandler);
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += value;
const chunks = buffer.split("\n\n");
buffer = chunks.pop() ?? "";
for (const chunk of chunks) {
const lines = chunk.split("\n");
const dataLines = [];
let eventName;
for (const line of lines) {
if (line.startsWith("data:")) {
dataLines.push(line.replace(/^data:\s*/, ""));
} else if (line.startsWith("event:")) {
eventName = line.replace(/^event:\s*/, "");
} else if (line.startsWith("id:")) {
lastEventId = line.replace(/^id:\s*/, "");
} else if (line.startsWith("retry:")) {
const parsed = Number.parseInt(
line.replace(/^retry:\s*/, ""),
10
);
if (!Number.isNaN(parsed)) {
retryDelay = parsed;
}
}
}
let data;
let parsedJson = false;
if (dataLines.length) {
const rawData = dataLines.join("\n");
try {
data = JSON.parse(rawData);
parsedJson = true;
} catch {
data = rawData;
}
}
if (parsedJson) {
if (responseValidator) {
await responseValidator(data);
}
if (responseTransformer) {
data = await responseTransformer(data);
}
}
onSseEvent?.({
data,
event: eventName,
id: lastEventId,
retry: retryDelay
});
if (dataLines.length) {
yield data;
}
}
}
} finally {
signal.removeEventListener("abort", abortHandler);
reader.releaseLock();
}
break;
} catch (error) {
onSseError?.(error);
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
break;
}
const backoff = Math.min(
retryDelay * 2 ** (attempt - 1),
sseMaxRetryDelay ?? 3e4
);
await sleep(backoff);
}
}
};
const stream = createStream();
return { stream };
};
const separatorArrayExplode = (style) => {
switch (style) {
case "label":
return ".";
case "matrix":
return ";";
case "simple":
return ",";
default:
return "&";
}
};
const separatorArrayNoExplode = (style) => {
switch (style) {
case "form":
return ",";
case "pipeDelimited":
return "|";
case "spaceDelimited":
return "%20";
default:
return ",";
}
};
const separatorObjectExplode = (style) => {
switch (style) {
case "label":
return ".";
case "matrix":
return ";";
case "simple":
return ",";
default:
return "&";
}
};
const serializeArrayParam = ({
allowReserved,
explode,
name,
style,
value
}) => {
if (!explode) {
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
switch (style) {
case "label":
return `.${joinedValues2}`;
case "matrix":
return `;${name}=${joinedValues2}`;
case "simple":
return joinedValues2;
default:
return `${name}=${joinedValues2}`;
}
}
const separator = separatorArrayExplode(style);
const joinedValues = value.map((v) => {
if (style === "label" || style === "simple") {
return allowReserved ? v : encodeURIComponent(v);
}
return serializePrimitiveParam({
allowReserved,
name,
value: v
});
}).join(separator);
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
};
const serializePrimitiveParam = ({
allowReserved,
name,
value
}) => {
if (value === void 0 || value === null) {
return "";
}
if (typeof value === "object") {
throw new Error(
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
);
}
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
};
const serializeObjectParam = ({
allowReserved,
explode,
name,
style,
value,
valueOnly
}) => {
if (value instanceof Date) {
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
}
if (style !== "deepObject" && !explode) {
let values = [];
Object.entries(value).forEach(([key, v]) => {
values = [
...values,
key,
allowReserved ? v : encodeURIComponent(v)
];
});
const joinedValues2 = values.join(",");
switch (style) {
case "form":
return `${name}=${joinedValues2}`;
case "label":
return `.${joinedValues2}`;
case "matrix":
return `;${name}=${joinedValues2}`;
default:
return joinedValues2;
}
}
const separator = separatorObjectExplode(style);
const joinedValues = Object.entries(value).map(
([key, v]) => serializePrimitiveParam({
allowReserved,
name: style === "deepObject" ? `${name}[${key}]` : key,
value: v
})
).join(separator);
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
};
const PATH_PARAM_RE = /\{[^{}]+\}/g;
const defaultPathSerializer = ({ path, url: _url }) => {
let url = _url;
const matches = _url.match(PATH_PARAM_RE);
if (matches) {
for (const match of matches) {
let explode = false;
let name = match.substring(1, match.length - 1);
let style = "simple";
if (name.endsWith("*")) {
explode = true;
name = name.substring(0, name.length - 1);
}
if (name.startsWith(".")) {
name = name.substring(1);
style = "label";
} else if (name.startsWith(";")) {
name = name.substring(1);
style = "matrix";
}
const value = path[name];
if (value === void 0 || value === null) {
continue;
}
if (Array.isArray(value)) {
url = url.replace(
match,
serializeArrayParam({ explode, name, style, value })
);
continue;
}
if (typeof value === "object") {
url = url.replace(
match,
serializeObjectParam({
explode,
name,
style,
value,
valueOnly: true
})
);
continue;
}
if (style === "matrix") {
url = url.replace(
match,
`;${serializePrimitiveParam({
name,
value
})}`
);
continue;
}
const replaceValue = encodeURIComponent(
style === "label" ? `.${value}` : value
);
url = url.replace(match, replaceValue);
}
}
return url;
};
const getUrl = ({
baseUrl,
path,
query,
querySerializer,
url: _url
}) => {
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
let url = (baseUrl ?? "") + pathUrl;
if (path) {
url = defaultPathSerializer({ path, url });
}
let search = query ? querySerializer(query) : "";
if (search.startsWith("?")) {
search = search.substring(1);
}
if (search) {
url += `?${search}`;
}
return url;
};
function getValidRequestBody(options) {
const hasBody = options.body !== void 0;
const isSerializedBody = hasBody && options.bodySerializer;
if (isSerializedBody) {
if ("serializedBody" in options) {
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
return hasSerializedBody ? options.serializedBody : null;
}
return options.body !== "" ? options.body : null;
}
if (hasBody) {
return options.body;
}
return void 0;
}
const getAuthToken = async (auth, callback) => {
const token = typeof callback === "function" ? await callback(auth) : callback;
if (!token) {
return;
}
if (auth.scheme === "bearer") {
return `Bearer ${token}`;
}
if (auth.scheme === "basic") {
return `Basic ${btoa(token)}`;
}
return token;
};
const createQuerySerializer = ({
allowReserved,
array,
object
} = {}) => {
const querySerializer = (queryParams) => {
const search = [];
if (queryParams && typeof queryParams === "object") {
for (const name in queryParams) {
const value = queryParams[name];
if (value === void 0 || value === null) {
continue;
}
if (Array.isArray(value)) {
const serializedArray = serializeArrayParam({
allowReserved,
explode: true,
name,
style: "form",
value,
...array
});
if (serializedArray) search.push(serializedArray);
} else if (typeof value === "object") {
const serializedObject = serializeObjectParam({
allowReserved,
explode: true,
name,
style: "deepObject",
value,
...object
});
if (serializedObject) search.push(serializedObject);
} else {
const serializedPrimitive = serializePrimitiveParam({
allowReserved,
name,
value
});
if (serializedPrimitive) search.push(serializedPrimitive);
}
}
}
return search.join("&");
};
return querySerializer;
};
const getParseAs = (contentType) => {
if (!contentType) {
return "stream";
}
const cleanContent = contentType.split(";")[0]?.trim();
if (!cleanContent) {
return;
}
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
return "json";
}
if (cleanContent === "multipart/form-data") {
return "formData";
}
if (["application/", "audio/", "image/", "video/"].some(
(type) => cleanContent.startsWith(type)
)) {
return "blob";
}
if (cleanContent.startsWith("text/")) {
return "text";
}
return;
};
const checkForExistence = (options, name) => {
if (!name) {
return false;
}
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
return true;
}
return false;
};
const setAuthParams = async ({
security,
...options
}) => {
for (const auth of security) {
if (checkForExistence(options, auth.name)) {
continue;
}
const token = await getAuthToken(auth, options.auth);
if (!token) {
continue;
}
const name = auth.name ?? "Authorization";
switch (auth.in) {
case "query":
if (!options.query) {
options.query = {};
}
options.query[name] = token;
break;
case "cookie":
options.headers.append("Cookie", `${name}=${token}`);
break;
case "header":
default:
options.headers.set(name, token);
break;
}
}
};
const buildUrl = (options) => getUrl({
baseUrl: options.baseUrl,
path: options.path,
query: options.query,
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
url: options.url
});
const mergeConfigs = (a, b) => {
const config = { ...a, ...b };
if (config.baseUrl?.endsWith("/")) {
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
}
config.headers = mergeHeaders(a.headers, b.headers);
return config;
};
const headersEntries = (headers) => {
const entries = [];
headers.forEach((value, key) => {
entries.push([key, value]);
});
return entries;
};
const mergeHeaders = (...headers) => {
const mergedHeaders = new Headers();
for (const header of headers) {
if (!header) {
continue;
}
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
for (const [key, value] of iterator) {
if (value === null) {
mergedHeaders.delete(key);
} else if (Array.isArray(value)) {
for (const v of value) {
mergedHeaders.append(key, v);
}
} else if (value !== void 0) {
mergedHeaders.set(
key,
typeof value === "object" ? JSON.stringify(value) : value
);
}
}
}
return mergedHeaders;
};
class Interceptors {
fns = [];
clear() {
this.fns = [];
}
eject(id) {
const index = this.getInterceptorIndex(id);
if (this.fns[index]) {
this.fns[index] = null;
}
}
exists(id) {
const index = this.getInterceptorIndex(id);
return Boolean(this.fns[index]);
}
getInterceptorIndex(id) {
if (typeof id === "number") {
return this.fns[id] ? id : -1;
}
return this.fns.indexOf(id);
}
update(id, fn) {
const index = this.getInterceptorIndex(id);
if (this.fns[index]) {
this.fns[index] = fn;
return id;
}
return false;
}
use(fn) {
this.fns.push(fn);
return this.fns.length - 1;
}
}
const createInterceptors = () => ({
error: new Interceptors(),
request: new Interceptors(),
response: new Interceptors()
});
const defaultQuerySerializer = createQuerySerializer({
allowReserved: false,
array: {
explode: true,
style: "form"
},
object: {
explode: true,
style: "deepObject"
}
});
const defaultHeaders = {
"Content-Type": "application/json"
};
const createConfig = (override = {}) => ({
...jsonBodySerializer,
headers: defaultHeaders,
parseAs: "auto",
querySerializer: defaultQuerySerializer,
...override
});
const createClient = (config = {}) => {
let _config = mergeConfigs(createConfig(), config);
const getConfig = () => ({ ..._config });
const setConfig = (config2) => {
_config = mergeConfigs(_config, config2);
return getConfig();
};
const interceptors = createInterceptors();
const beforeRequest = async (options) => {
const opts = {
..._config,
...options,
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
headers: mergeHeaders(_config.headers, options.headers),
serializedBody: void 0
};
if (opts.security) {
await setAuthParams({
...opts,
security: opts.security
});
}
if (opts.requestValidator) {
await opts.requestValidator(opts);
}
if (opts.body !== void 0 && opts.bodySerializer) {
opts.serializedBody = opts.bodySerializer(opts.body);
}
if (opts.body === void 0 || opts.serializedBody === "") {
opts.headers.delete("Content-Type");
}
const url = buildUrl(opts);
return { opts, url };
};
const request = async (options) => {
const { opts, url } = await beforeRequest(options);
const requestInit = {
redirect: "follow",
...opts,
body: getValidRequestBody(opts)
};
let request2 = new Request(url, requestInit);
for (const fn of interceptors.request.fns) {
if (fn) {
request2 = await fn(request2, opts);
}
}
const _fetch = opts.fetch;
let response = await _fetch(request2);
for (const fn of interceptors.response.fns) {
if (fn) {
response = await fn(response, request2, opts);
}
}
const result = {
request: request2,
response
};
if (response.ok) {
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
let emptyData;
switch (parseAs) {
case "arrayBuffer":
case "blob":
case "text":
emptyData = await response[parseAs]();
break;
case "formData":
emptyData = new FormData();
break;
case "stream":
emptyData = response.body;
break;
case "json":
default:
emptyData = {};
break;
}
return opts.responseStyle === "data" ? emptyData : {
data: emptyData,
...result
};
}
let data;
switch (parseAs) {
case "arrayBuffer":
case "blob":
case "formData":
case "json":
case "text":
data = await response[parseAs]();
break;
case "stream":
return opts.responseStyle === "data" ? response.body : {
data: response.body,
...result
};
}
if (parseAs === "json") {
if (opts.responseValidator) {
await opts.responseValidator(data);
}
if (opts.responseTransformer) {
data = await opts.responseTransformer(data);
}
}
return opts.responseStyle === "data" ? data : {
data,
...result
};
}
const textError = await response.text();
let jsonError;
try {
jsonError = JSON.parse(textError);
} catch {
}
const error = jsonError ?? textError;
let finalError = error;
for (const fn of interceptors.error.fns) {
if (fn) {
finalError = await fn(error, response, request2, opts);
}
}
finalError = finalError || {};
if (opts.throwOnError) {
throw finalError;
}
return opts.responseStyle === "data" ? void 0 : {
error: finalError,
...result
};
};
const makeMethodFn = (method) => (options) => request({ ...options, method });
const makeSseFn = (method) => async (options) => {
const { opts, url } = await beforeRequest(options);
return createSseClient({
...opts,
body: opts.body,
headers: opts.headers,
method,
onRequest: async (url2, init) => {
let request2 = new Request(url2, init);
for (const fn of interceptors.request.fns) {
if (fn) {
request2 = await fn(request2, opts);
}
}
return request2;
},
url
});
};
return {
buildUrl,
connect: makeMethodFn("CONNECT"),
delete: makeMethodFn("DELETE"),
get: makeMethodFn("GET"),
getConfig,
head: makeMethodFn("HEAD"),
interceptors,
options: makeMethodFn("OPTIONS"),
patch: makeMethodFn("PATCH"),
post: makeMethodFn("POST"),
put: makeMethodFn("PUT"),
request,
setConfig,
sse: {
connect: makeSseFn("CONNECT"),
delete: makeSseFn("DELETE"),
get: makeSseFn("GET"),
head: makeSseFn("HEAD"),
options: makeSseFn("OPTIONS"),
patch: makeSseFn("PATCH"),
post: makeSseFn("POST"),
put: makeSseFn("PUT"),
trace: makeSseFn("TRACE")
},
trace: makeMethodFn("TRACE")
};
};
const createClientConfig = (config) => {
console.log("runtime config", config);
return {
...config,
fetch: fetchWithDestination
};
};
async function fetchWithDestination(input, init) {
const destination = await connectivity.getDestination({ destinationName: process.env.GIGYA_DESTINATION || process.env.CDC_DESTINATION || "cdc-api" });
if (connectivity.isHttpDestination(destination)) {
var response = await httpClient.executeHttpRequest(destination, {
method: init?.method || "GET",
url: input.toString(),
headers: init?.headers || {},
data: init?.body || void 0
});
return new Response(response.data, {
status: response.status,
headers: response.headers
});
}
throw new Error("Destination is not an HTTP destination", { cause: destination });
}
const client = createClient(createClientConfig(createConfig()));
const setAccountInfoResponseTransformer = async (data) => {
data = accountResponseSchemaResponseTransformer(data);
return data;
};
const accountResponseSchemaResponseTransformer = (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const okResponseSchemaResponseTransformer = (data) => {
data = basicResponseSchemaResponseTransformer(data);
data.time = new Date(data.time);
return data;
};
const basicResponseSchemaResponseTransformer = (data) => {
data.time = new Date(data.time);
return data;
};
const getAccountInfoResponseTransformer = async (data) => {
data = getAccountInfoResponseSchemaResponseTransformer(data);
return data;
};
const getAccountInfoResponseSchemaResponseTransformer = (data) => {
data = accountResponseSchemaResponseTransformer(data);
return data;
};
const dqmCredentialsSetResponseTransformer = async (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const accountsB2bSetupBootstrapResponseTransformer = async (data) => {
data = setupBootstrapResponseSchemaResponseTransformer(data);
return data;
};
const setupBootstrapResponseSchemaResponseTransformer = (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const accountsB2bSearchResponseTransformer = async (data) => {
data = b2bSearchResponseSchemaResponseTransformer(data);
return data;
};
const b2bSearchResponseSchemaResponseTransformer = (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const communicationUpdateResponseTransformer = async (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const dsSetSchemaResponseTransformer = async (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const dsGetResponseTransformer = async (data) => {
data = dsGetResponseSchemaResponseTransformer(data);
return data;
};
const dsGetResponseSchemaResponseTransformer = (data) => {
data = okResponseSchemaResponseTransformer(data);
if (data.object) {
data.object = dsObjectSchemaResponseTransformer(data.object);
}
return data;
};
const dsObjectSchemaResponseTransformer = (data) => {
if (data.lastUpdated) {
data.lastUpdated = BigInt(data.lastUpdated.toString());
}
if (data.created) {
data.created = BigInt(data.created.toString());
}
return data;
};
const dsStoreResponseTransformer = async (data) => {
data = dsStoreResponseSchemaResponseTransformer(data);
return data;
};
const dsStoreResponseSchemaResponseTransformer = (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const dsSearchResponseTransformer = async (data) => {
data = dsSearchResponseSchemaResponseTransformer(data);
return data;
};
const dsSearchResponseSchemaResponseTransformer = (data) => {
data = okResponseSchemaResponseTransformer(data);
if (data.results) {
data.results = data.results.map((item) => {
return dsObjectSchemaResponseTransformer(item);
});
}
return data;
};
const accountsGroupsGetGroupMemberInfoResponseTransformer = async (data) => {
data = getGroupMemberInfoResponseSchemaResponseTransformer(data);
return data;
};
const getGroupMemberInfoResponseSchemaResponseTransformer = (data) => {
if (data.result) {
data.result = memberInfoSchemaResponseTransformer(data.result);
}
return data;
};
const memberInfoSchemaResponseTransformer = (data) => {
if (data.memberSince) {
data.memberSince = new Date(data.memberSince);
}
if (data.lastUpdated) {
data.lastUpdated = new Date(data.lastUpdated);
}
if (data.memberSinceTimestamp) {
data.memberSinceTimestamp = BigInt(data.memberSinceTimestamp.toString());
}
if (data.lastUpdatedTimestamp) {
data.lastUpdatedTimestamp = BigInt(data.lastUpdatedTimestamp.toString());
}
return data;
};
const accountsGroupsGetGroupInfoResponseTransformer = async (data) => {
data = getGroupInfoResponseSchemaResponseTransformer(data);
return data;
};
const getGroupInfoResponseSchemaResponseTransformer = (data) => {
if (data.memberSince) {
data.memberSince = new Date(data.memberSince);
}
if (data.lastUpdated) {
data.lastUpdated = new Date(data.lastUpdated);
}
return data;
};
const accountsGroupsGetAllMemberGroupsResponseTransformer = async (data) => {
data = getAllMemberGroupsResponseSchemaResponseTransformer(data);
return data;
};
const getAllMemberGroupsResponseSchemaResponseTransformer = (data) => {
data = memberInfoSchemaResponseTransformer(data);
return data;
};
const workflowInstancesGetResponseTransformer = async (data) => {
data = workflowInstanceSchemaResponseTransformer(data);
return data;
};
const workflowInstanceSchemaResponseTransformer = (data) => {
if (data.fault) {
data.fault = workflowFaultSchemaResponseTransformer(data.fault);
}
return data;
};
const workflowFaultSchemaResponseTransformer = (data) => {
if (data.exception) {
data.exception = simpleExceptionSchemaResponseTransformer(data.exception);
}
return data;
};
const simpleExceptionSchemaResponseTransformer = (data) => {
if (data.innerException) {
data.innerException = simpleExceptionSchemaResponseTransformer(data.innerException);
}
return data;
};
const updateStatisticsSchedulingResponseTransformer = async (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const getStatisticsSchedulingResponseTransformer = async (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const deleteStatisticsSchedulingResponseTransformer = async (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const addressSuggestionsGetResponseTransformer = async (data) => {
data = addressSuggestionsResponseSchemaResponseTransformer(data);
return data;
};
const addressSuggestionsResponseSchemaResponseTransformer = (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const addressSuggestionsSelectResponseTransformer = async (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
const phonenumberValidateResponseTransformer = async (data) => {
data = phoneNumberValidationResponseSchemaResponseTransformer(data);
return data;
};
const phoneNumberValidationResponseSchemaResponseTransformer = (data) => {
data = okResponseSchemaResponseTransformer(data);
return data;
};
class setup {
/**
* create predefined policies and building blocks required integration, for example SAP Commerce Cloud.
*/
static bootstrap(options) {
return (options?.client ?? client).get({
responseTransformer: accountsB2bSetupBootstrapResponseTransformer,
security: [
{
in: "query",
name: "apiKey",
type: "apiKey"
}
],
url: "/accounts.b2b.setup.bootstrap",
...options
});
}
}
class b2B {
/**
* Searches and retrieves Organizations data from SAP Customer Data Cloud's Storage using an SQL-like query.
*
*
*
* ## Query Syntax
* Gigya queries use the same syntax rules as SQL, but not all standard SQL key words are available. Unsupported SQL syntax in the query string, such as "HAVING", will produce an error.
*
* The query string clauses must appear in the following order (Queries ordered differently will produce an error):
*
* ```SELECT ... FROM ... WHERE ... FILTER ... ORDER BY ... LIMIT```
*
*
* ### SELECT
* Only ```*``` supported as all fields will always be returned
*
* ### FROM
* Name of the data source. Only one data source is supported.
* The available data sources are: ```organizations```, ```organization_requests```
* * organizations - retrieve organization details
* * organization_requests - retrieve organization requests details
*
* ### WHERE
* The _where_ clause defines conditions for selecting items from the collection.
*
* Supported operators:
*
* + __> , >=, <, <= , = , !=__ - the left operand must be a data field name (with a proper suffix letter) and the right operand must be a constant of the same type as the field. For example: "WHERE profile.age >= 18 ".
* + __AND__ (no support for OR)
* + __CONTAINS, NOT CONTAINS__ - may be used only on text (string) fields.
* Text (string) fields - supports standard full text search capabilities.
* Contains is not case sensitive.
* The left operand must be a text field name and the right operand
* must be a constant string.
* + __IN()__ - only retrieve items if the field contains one of the list values
* + __NOT__
*
* ### ORDER BY
* Use _ORDER BY_ to enter a list of fields by which to sort the result objects.
* Sorting direction:
* + __ASC__
* + __DESC__
*
* ### LIMIT
* Use _LIMIT_ to specify the maximum number of returned result objects.
* If not specified, the default is 300.
* The maximum limit value accepted is 1000.
* If the search is sent with openCursor = true, limit will set the batch size.
* Please note, when using a cursor, the number of results in a batch is not guaranteed.
*
* __Note__
* When implementing paging, there is no guarantee against duplications or that recently added data will show up in the query results.
*
* #### For retrieve Organization Details use following Sql Syntax
* ```SQL
* select * from organizations
* ```
*
* #### For retrieve Organization Requests Details use following Sql Syntax
* ```SQL
* select * from organization_requests
* ```
*
*/
static search(options) {
return (options?.client ?? client).post({
...urlSearchParamsBodySerializer,
responseTransformer: accountsB2bSearchResponseTransformer,
security: [
{
scheme: "bearer",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.b2b.search",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options?.headers
}
});
}
static setup = setup;
}
class groups {
/**
* Create a new model
*/
static createModel(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.createModel",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Delete a model
*/
static deleteModel(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.deleteModel",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Get all models
*/
static getAllModels(options) {
return (options?.client ?? client).post({
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.getAllModels",
...options
});
}
/**
* This API creates a new group
*/
static registerGroup(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.registerGroup",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* This API updates an existing Group's information
*/
static setGroupInfo(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.setGroupInfo",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Assign a member to a group
*/
static assignGroupMember(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.assignGroupMember",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Update information about a group member
*/
static setGroupMemberInfo(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "bearer",
type: "http"
},
{
scheme: "basic",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
}
],
url: "/accounts.groups.setGroupMemberInfo",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Get information about a group member
*/
static getGroupMemberInfo(options) {
return (options?.client ?? client).post({
...urlSearchParamsBodySerializer,
responseTransformer: accountsGroupsGetGroupMemberInfoResponseTransformer,
security: [
{
scheme: "bearer",
type: "http"
},
{
scheme: "basic",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
}
],
url: "/accounts.groups.getGroupMemberInfo",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options?.headers
}
});
}
/**
* Remove a member from a group
*/
static removeMember(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "bearer",
type: "http"
},
{
scheme: "basic",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
}
],
url: "/accounts.groups.removeMember",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Create a new group invitation
*/
static createInvitation(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.createInvitation",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Confirm a group invitation
*/
static invitationConfirm(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "bearer",
type: "http"
},
{
scheme: "basic",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
}
],
url: "/accounts.groups.invitationConfirm",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Finalize a group invitation
*/
static finalizeInvitation(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "bearer",
type: "http"
},
{
scheme: "basic",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
}
],
url: "/accounts.groups.finalizeInvitation",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Set site configuration
*/
static setSiteConfig(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.setSiteConfig",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Get information about a group
*/
static getGroupInfo(options) {
return (options?.client ?? client).get({
...urlSearchParamsBodySerializer,
responseTransformer: accountsGroupsGetGroupInfoResponseTransformer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.getGroupInfo",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options?.headers
}
});
}
/**
* Get all groups that a member belongs to
*/
static getAllMemberGroups(options) {
return (options?.client ?? client).get({
...urlSearchParamsBodySerializer,
responseTransformer: accountsGroupsGetAllMemberGroupsResponseTransformer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.getAllMemberGroups",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options?.headers
}
});
}
/**
* Set a group's data schema
*/
static setSchema(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.setSchema",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Get a group's data schema
*/
static getSchema(options) {
return (options?.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.getSchema",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options?.headers
}
});
}
/**
* Delete a field from a group's data schema
*/
static deleteSchemaField(options) {
return (options?.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.groups.deleteSchemaField",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options?.headers
}
});
}
}
class accounts {
/**
* Set Account Info.
*
* Update account properties
*/
static setAccountInfo(options) {
return (options?.client ?? client).post({
...formDataBodySerializer,
responseTransformer: setAccountInfoResponseTransformer,
security: [
{
scheme: "bearer",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
},
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.setAccountInfo",
...options,
headers: {
"Content-Type": null,
...options?.headers
}
});
}
/**
* Get Account Info.
*
* Get the account properties.
*/
static getAccountInfo(options) {
return (options.client ?? client).get({
responseTransformer: getAccountInfoResponseTransformer,
security: [
{
scheme: "bearer",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
},
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.getAccountInfo",
...options
});
}
static b2B = b2B;
static groups = groups;
}
class credentials {
static get(options) {
return (options?.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
in: "query",
name: "partnerId",
type: "apiKey"
},
{
scheme: "basic",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
}
],
url: "/admin.dqm.credentials.get",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options?.headers
}
});
}
static set(options) {
return (options?.client ?? client).post({
...urlSearchParamsBodySerializer,
responseTransformer: dqmCredentialsSetResponseTransformer,
security: [
{
in: "query",
name: "partnerId",
type: "apiKey"
},
{
scheme: "basic",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
}
],
url: "/admin.dqm.credentials.set",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options?.headers
}
});
}
}
class dqm {
static credentials = credentials;
}
class communication {
/**
* Update Communication Properties.
*
* Update Communication Properties.
*/
static update(options) {
return (options?.client ?? client).post({
responseTransformer: communicationUpdateResponseTransformer,
security: [
{
scheme: "bearer",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
},
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.communication.set",
...options,
headers: {
"Content-Type": "application/json",
...options?.headers
}
});
}
/**
* Get Communication Properties.
*
* Get Communication Properties. <br />
*/
static get(options) {
return (options.client ?? client).get({
security: [
{
scheme: "bearer",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
},
{
scheme: "basic",
type: "http"
}
],
url: "/accounts.communication.get",
...options
});
}
}
class ds {
/**
* Set schema
*/
static setSchema(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
responseTransformer: dsSetSchemaResponseTransformer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/ds.setSchema",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Get schema
*/
static getSchema(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
security: [
{
in: "query",
name: "apiKey",
type: "apiKey"
}
],
url: "/ds.getSchema",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Get object
*/
static get(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
responseTransformer: dsGetResponseTransformer,
security: [
{
scheme: "bearer",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
},
{
scheme: "basic",
type: "http"
}
],
url: "/ds.get",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Store object
*/
static store(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
responseTransformer: dsStoreResponseTransformer,
security: [
{
scheme: "bearer",
type: "http"
},
{
in: "query",
name: "apiKey",
type: "apiKey"
},
{
in: "query",
name: "uid",
type: "apiKey"
},
{
scheme: "basic",
type: "http"
}
],
url: "/ds.store",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
/**
* Search objects
*/
static search(options) {
return (options.client ?? client).post({
...urlSearchParamsBodySerializer,
responseTransformer: dsSearchResponseTransformer,
security: [
{
scheme: "basic",
type: "http"
}
],
url: "/ds.search",
...options,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...options.headers
}
});
}
}