@wix/api-client
Advanced tools
Comparing version 1.1.76 to 1.2.0
@@ -5,3 +5,3 @@ "use strict"; | ||
describe('biHeaderGenerator', () => { | ||
const requestOptions = { | ||
const apiMetadata = { | ||
methodFqn: 'some.method.fqn', | ||
@@ -14,7 +14,7 @@ entityFqdn: 'wix.test.v1.foo' | ||
it('should generate an object with a single header', () => { | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(requestOptions, publicMetadata); | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(apiMetadata, publicMetadata); | ||
expect(Object.keys(result)).toHaveLength(1); | ||
}); | ||
it('should generate the correct BI header name', () => { | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(requestOptions, publicMetadata); | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(apiMetadata, publicMetadata); | ||
expect(result).toHaveProperty('x-wix-bi-gateway'); | ||
@@ -25,3 +25,3 @@ }); | ||
it('should generate a valid multi value field', () => { | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(requestOptions, publicMetadata); | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(apiMetadata, publicMetadata); | ||
const value = result[_biHeaderGenerator.WixBIHeaderName]; | ||
@@ -37,8 +37,16 @@ expect(value).toEqual('environment=js-sdk,package-name=@wix/some-package,method-fqn=some.method.fqn,entity=wix.test.v1.foo'); | ||
it('should include a package name key if it is specified', () => { | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(requestOptions, publicMetadata); | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(apiMetadata, publicMetadata); | ||
const value = result[_biHeaderGenerator.WixBIHeaderName]; | ||
expect(value).toMatch(/package-name=@wix\/some-package/); | ||
}); | ||
it('should prioritize the package name from the request options', () => { | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)({ | ||
...apiMetadata, | ||
packageName: 'the-package' | ||
}, publicMetadata); | ||
const value = result[_biHeaderGenerator.WixBIHeaderName]; | ||
expect(value).toMatch(/package-name=the-package/); | ||
}); | ||
it('should include a method fqn key if it specified', () => { | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(requestOptions, publicMetadata); | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(apiMetadata, publicMetadata); | ||
const value = result[_biHeaderGenerator.WixBIHeaderName]; | ||
@@ -48,3 +56,3 @@ expect(value).toMatch(/method-fqn=some.method.fqn/); | ||
it('should include an entity key set if it is specified', () => { | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(requestOptions, publicMetadata); | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(apiMetadata, publicMetadata); | ||
const value = result[_biHeaderGenerator.WixBIHeaderName]; | ||
@@ -54,3 +62,3 @@ expect(value).toMatch(/entity=wix.test.v1.foo/); | ||
it('should not include a package name key if it is not specified', () => { | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(requestOptions, {}); | ||
const result = (0, _biHeaderGenerator.biHeaderGenerator)(apiMetadata, {}); | ||
const value = result[_biHeaderGenerator.WixBIHeaderName]; | ||
@@ -57,0 +65,0 @@ expect(value).not.toMatch(/package-name=/); |
@@ -227,25 +227,65 @@ "use strict"; | ||
it('should support host modules', async () => { | ||
const aHost = { | ||
aHostFunction: a => Promise.resolve(a + 1), | ||
getAuth: () => `the-auth-token` | ||
}; | ||
const hostModule = { | ||
__type: 'host', | ||
create: () => ({ | ||
aHostFunction: a => Promise.resolve(a + 1) | ||
}), | ||
auth() { | ||
return { | ||
getAuthHeaders: async () => ({ | ||
headers: {} | ||
}) | ||
}; | ||
} | ||
create: host => ({ | ||
aHostFunction: a => host.aHostFunction(a) | ||
}) | ||
}; | ||
const client = (0, _wixClient.createClient)({ | ||
host: aHost, | ||
modules: { | ||
hostModule | ||
}, | ||
auth: hostModule.auth() | ||
auth: { | ||
getAuthHeaders: async () => ({ | ||
headers: {} | ||
}) | ||
} | ||
}); | ||
expect(client.hostModule.aHostFunction(1)).resolves.toBe(2); | ||
}); | ||
it('should pass host to the authentication strategy to get headers', async () => { | ||
const aHost = { | ||
getAuth: () => `the-auth-token` | ||
}; | ||
// @ts-expect-error | ||
global.fetch = jest.fn(() => Promise.resolve({ | ||
status: 200, | ||
json: () => Promise.resolve({ | ||
cart: { | ||
id: 'cart-id', | ||
lineItems: [] | ||
} | ||
}) | ||
})); | ||
const auth = () => { | ||
return { | ||
getAuthHeaders: async host => ({ | ||
headers: { | ||
Authorization: host.getAuth() | ||
} | ||
}) | ||
}; | ||
}; | ||
const client = (0, _wixClient.createClient)({ | ||
host: aHost, | ||
modules: { | ||
currentCart: _ecom.currentCart | ||
}, | ||
auth: auth() | ||
}); | ||
await client.currentCart.getCurrentCart(); | ||
expect(global.fetch).toHaveBeenCalledWith('https://www.wixapis.com/ecom/v1/carts/current', expect.objectContaining({ | ||
headers: expect.objectContaining({ | ||
Authorization: 'the-auth-token' | ||
}) | ||
})); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=wixClient.spec.js.map |
@@ -8,9 +8,9 @@ "use strict"; | ||
exports.WixBIHeaderName = WixBIHeaderName; | ||
function biHeaderGenerator(requestOptions, publicMetadata) { | ||
function biHeaderGenerator(apiMetadata, publicMetadata) { | ||
return { | ||
[WixBIHeaderName]: objectToKeyValue({ | ||
environment: 'js-sdk', | ||
'package-name': publicMetadata == null ? void 0 : publicMetadata.PACKAGE_NAME, | ||
'method-fqn': requestOptions == null ? void 0 : requestOptions.methodFqn, | ||
entity: requestOptions == null ? void 0 : requestOptions.entityFqdn | ||
'package-name': apiMetadata.packageName ?? (publicMetadata == null ? void 0 : publicMetadata.PACKAGE_NAME), | ||
'method-fqn': apiMetadata.methodFqn, | ||
entity: apiMetadata.entityFqdn | ||
}) | ||
@@ -17,0 +17,0 @@ }; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.getDefaultContentHeader = void 0; | ||
exports.isObject = exports.getDefaultContentHeader = void 0; | ||
// we follow a simplified version of the axios convention | ||
@@ -16,2 +16,4 @@ // https://github.com/axios/axios/blob/649d739288c8e2c55829ac60e2345a0f3439c730/lib/defaults/index.js#L65 | ||
exports.getDefaultContentHeader = getDefaultContentHeader; | ||
const isObject = val => val && typeof val === 'object' && !Array.isArray(val); | ||
exports.isObject = isObject; | ||
//# sourceMappingURL=helpers.js.map |
@@ -5,75 +5,24 @@ "use strict"; | ||
exports.createClient = createClient; | ||
var _biHeaderGenerator = require("./bi/biHeaderGenerator"); | ||
var _common = require("./common"); | ||
var _helpers = require("./helpers"); | ||
const wrapperBuilder = (origFunc, publicMetadata, boundFetch | ||
// @ts-expect-error | ||
) => { | ||
return origFunc({ | ||
request: async factory => { | ||
const requestOptions = factory({ | ||
host: _common.API_URL | ||
}); | ||
let url = `https://${_common.API_URL}${requestOptions.url}`; | ||
if (requestOptions.params && requestOptions.params.toString()) { | ||
url += `?${requestOptions.params.toString()}`; | ||
} | ||
try { | ||
const biHeader = (0, _biHeaderGenerator.biHeaderGenerator)(requestOptions, publicMetadata); | ||
const res = await boundFetch(url, { | ||
method: requestOptions.method, | ||
...(requestOptions.data && { | ||
body: JSON.stringify(requestOptions.data) | ||
}), | ||
headers: { | ||
...biHeader | ||
} | ||
}); | ||
if (res.status !== 200) { | ||
var _dataError, _dataError2; | ||
let dataError = null; | ||
try { | ||
dataError = await res.json(); | ||
} catch (e) { | ||
// | ||
} | ||
throw errorBuilder(res.status, (_dataError = dataError) == null ? void 0 : _dataError.message, (_dataError2 = dataError) == null ? void 0 : _dataError2.details, { | ||
requestId: res.headers.get('X-Wix-Request-Id'), | ||
details: dataError | ||
}); | ||
} | ||
const data = await res.json(); | ||
return { | ||
data | ||
}; | ||
} catch (e) { | ||
var _e$message; | ||
if ((_e$message = e.message) != null && _e$message.includes('fetch is not defined')) { | ||
console.error('Node.js v18+ is required'); | ||
} | ||
throw e; | ||
} | ||
} | ||
}); | ||
}; | ||
const errorBuilder = (code, description, details, data) => { | ||
return { | ||
response: { | ||
data: { | ||
details: { | ||
...(!(details != null && details.validationError) && { | ||
applicationError: { | ||
description, | ||
code, | ||
data | ||
} | ||
}), | ||
...details | ||
}, | ||
message: description | ||
}, | ||
status: code | ||
} | ||
}; | ||
}; | ||
var _restModules = require("./rest-modules"); | ||
var _hostModules = require("./host-modules"); | ||
/** | ||
* This type takes in a descriptors object of a certain Host (including an `unknown` host) | ||
* and returns an object with the same structure, but with all descriptors replaced with their API. | ||
* Any non-descriptor properties are removed from the returned object, including descriptors that | ||
* do not match the given host (as they will not work with the given host). | ||
*/ | ||
/** | ||
* Descriptors are objects that describe the API of a module, and the module | ||
* can either be a REST module or a host module. | ||
* This type is recursive, so it can describe nested modules. | ||
*/ | ||
/** | ||
* This type is used in `createClient` to ensure that the given host matches the host of the given descriptors. | ||
* If the host does not match, the descriptor is replaced with a host module that will throw an error when used. | ||
*/ | ||
function createClient(config) { | ||
@@ -89,3 +38,3 @@ const _headers = config.headers || { | ||
const boundFetch = async (url, options) => { | ||
const authHeaders = await authStrategy.getAuthHeaders(); | ||
const authHeaders = await authStrategy.getAuthHeaders(config.host); | ||
const defaultContentTypeHeader = (0, _helpers.getDefaultContentHeader)(options); | ||
@@ -102,14 +51,10 @@ return fetch(url, { | ||
}; | ||
const isObject = val => val && typeof val === 'object' && !Array.isArray(val); | ||
const isHostModule = val => isObject(val) && val.__type === 'host'; | ||
const traverse = obj => { | ||
return Object.entries(obj).reduce((prev, [key, value]) => { | ||
if (isObject(value)) { | ||
if (isHostModule(value)) { | ||
prev[key] = value.create(); | ||
} else { | ||
prev[key] = traverse(value); | ||
} | ||
if ((0, _hostModules.isHostModule)(value)) { | ||
prev[key] = (0, _hostModules.buildHostModule)(value, config.host); | ||
} else if (typeof obj[key] === 'function') { | ||
prev[key] = wrapperBuilder(value, obj[_common.PUBLIC_METADATA_KEY] ?? {}, boundFetch); | ||
prev[key] = (0, _restModules.buildRESTDescriptor)(value, obj[_common.PUBLIC_METADATA_KEY] ?? {}, boundFetch); | ||
} else if ((0, _helpers.isObject)(value)) { | ||
prev[key] = traverse(value); | ||
} else { | ||
@@ -116,0 +61,0 @@ prev[key] = value; |
import { biHeaderGenerator, WixBIHeaderName } from '../bi/biHeaderGenerator'; | ||
describe('biHeaderGenerator', () => { | ||
const requestOptions = { | ||
const apiMetadata = { | ||
methodFqn: 'some.method.fqn', | ||
@@ -11,7 +11,7 @@ entityFqdn: 'wix.test.v1.foo' | ||
it('should generate an object with a single header', () => { | ||
const result = biHeaderGenerator(requestOptions, publicMetadata); | ||
const result = biHeaderGenerator(apiMetadata, publicMetadata); | ||
expect(Object.keys(result)).toHaveLength(1); | ||
}); | ||
it('should generate the correct BI header name', () => { | ||
const result = biHeaderGenerator(requestOptions, publicMetadata); | ||
const result = biHeaderGenerator(apiMetadata, publicMetadata); | ||
expect(result).toHaveProperty('x-wix-bi-gateway'); | ||
@@ -22,3 +22,3 @@ }); | ||
it('should generate a valid multi value field', () => { | ||
const result = biHeaderGenerator(requestOptions, publicMetadata); | ||
const result = biHeaderGenerator(apiMetadata, publicMetadata); | ||
const value = result[WixBIHeaderName]; | ||
@@ -34,8 +34,16 @@ expect(value).toEqual('environment=js-sdk,package-name=@wix/some-package,method-fqn=some.method.fqn,entity=wix.test.v1.foo'); | ||
it('should include a package name key if it is specified', () => { | ||
const result = biHeaderGenerator(requestOptions, publicMetadata); | ||
const result = biHeaderGenerator(apiMetadata, publicMetadata); | ||
const value = result[WixBIHeaderName]; | ||
expect(value).toMatch(/package-name=@wix\/some-package/); | ||
}); | ||
it('should prioritize the package name from the request options', () => { | ||
const result = biHeaderGenerator({ | ||
...apiMetadata, | ||
packageName: 'the-package' | ||
}, publicMetadata); | ||
const value = result[WixBIHeaderName]; | ||
expect(value).toMatch(/package-name=the-package/); | ||
}); | ||
it('should include a method fqn key if it specified', () => { | ||
const result = biHeaderGenerator(requestOptions, publicMetadata); | ||
const result = biHeaderGenerator(apiMetadata, publicMetadata); | ||
const value = result[WixBIHeaderName]; | ||
@@ -45,3 +53,3 @@ expect(value).toMatch(/method-fqn=some.method.fqn/); | ||
it('should include an entity key set if it is specified', () => { | ||
const result = biHeaderGenerator(requestOptions, publicMetadata); | ||
const result = biHeaderGenerator(apiMetadata, publicMetadata); | ||
const value = result[WixBIHeaderName]; | ||
@@ -51,3 +59,3 @@ expect(value).toMatch(/entity=wix.test.v1.foo/); | ||
it('should not include a package name key if it is not specified', () => { | ||
const result = biHeaderGenerator(requestOptions, {}); | ||
const result = biHeaderGenerator(apiMetadata, {}); | ||
const value = result[WixBIHeaderName]; | ||
@@ -54,0 +62,0 @@ expect(value).not.toMatch(/package-name=/); |
@@ -225,25 +225,65 @@ import { cart, currentCart } from '@wix/ecom'; | ||
it('should support host modules', async () => { | ||
const aHost = { | ||
aHostFunction: a => Promise.resolve(a + 1), | ||
getAuth: () => "the-auth-token" | ||
}; | ||
const hostModule = { | ||
__type: 'host', | ||
create: () => ({ | ||
aHostFunction: a => Promise.resolve(a + 1) | ||
}), | ||
auth() { | ||
return { | ||
getAuthHeaders: async () => ({ | ||
headers: {} | ||
}) | ||
}; | ||
} | ||
create: host => ({ | ||
aHostFunction: a => host.aHostFunction(a) | ||
}) | ||
}; | ||
const client = createClient({ | ||
host: aHost, | ||
modules: { | ||
hostModule | ||
}, | ||
auth: hostModule.auth() | ||
auth: { | ||
getAuthHeaders: async () => ({ | ||
headers: {} | ||
}) | ||
} | ||
}); | ||
expect(client.hostModule.aHostFunction(1)).resolves.toBe(2); | ||
}); | ||
it('should pass host to the authentication strategy to get headers', async () => { | ||
const aHost = { | ||
getAuth: () => "the-auth-token" | ||
}; | ||
// @ts-expect-error | ||
global.fetch = jest.fn(() => Promise.resolve({ | ||
status: 200, | ||
json: () => Promise.resolve({ | ||
cart: { | ||
id: 'cart-id', | ||
lineItems: [] | ||
} | ||
}) | ||
})); | ||
const auth = () => { | ||
return { | ||
getAuthHeaders: async host => ({ | ||
headers: { | ||
Authorization: host.getAuth() | ||
} | ||
}) | ||
}; | ||
}; | ||
const client = createClient({ | ||
host: aHost, | ||
modules: { | ||
currentCart | ||
}, | ||
auth: auth() | ||
}); | ||
await client.currentCart.getCurrentCart(); | ||
expect(global.fetch).toHaveBeenCalledWith('https://www.wixapis.com/ecom/v1/carts/current', expect.objectContaining({ | ||
headers: expect.objectContaining({ | ||
Authorization: 'the-auth-token' | ||
}) | ||
})); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=wixClient.spec.js.map |
export const WixBIHeaderName = 'x-wix-bi-gateway'; | ||
export function biHeaderGenerator(requestOptions, publicMetadata) { | ||
export function biHeaderGenerator(apiMetadata, publicMetadata) { | ||
var _apiMetadata$packageN; | ||
return { | ||
[WixBIHeaderName]: objectToKeyValue({ | ||
environment: 'js-sdk', | ||
'package-name': publicMetadata == null ? void 0 : publicMetadata.PACKAGE_NAME, | ||
'method-fqn': requestOptions == null ? void 0 : requestOptions.methodFqn, | ||
entity: requestOptions == null ? void 0 : requestOptions.entityFqdn | ||
'package-name': (_apiMetadata$packageN = apiMetadata.packageName) != null ? _apiMetadata$packageN : publicMetadata == null ? void 0 : publicMetadata.PACKAGE_NAME, | ||
'method-fqn': apiMetadata.methodFqn, | ||
entity: apiMetadata.entityFqdn | ||
}) | ||
@@ -10,0 +11,0 @@ }; |
@@ -11,2 +11,3 @@ // we follow a simplified version of the axios convention | ||
}; | ||
export const isObject = val => val && typeof val === 'object' && !Array.isArray(val); | ||
//# sourceMappingURL=helpers.js.map |
@@ -1,74 +0,24 @@ | ||
import { biHeaderGenerator } from './bi/biHeaderGenerator'; | ||
import { PUBLIC_METADATA_KEY, API_URL } from './common'; | ||
import { getDefaultContentHeader } from './helpers'; | ||
const wrapperBuilder = (origFunc, publicMetadata, boundFetch | ||
// @ts-expect-error | ||
) => { | ||
return origFunc({ | ||
request: async factory => { | ||
const requestOptions = factory({ | ||
host: API_URL | ||
}); | ||
let url = "https://" + API_URL + requestOptions.url; | ||
if (requestOptions.params && requestOptions.params.toString()) { | ||
url += "?" + requestOptions.params.toString(); | ||
} | ||
try { | ||
const biHeader = biHeaderGenerator(requestOptions, publicMetadata); | ||
const res = await boundFetch(url, { | ||
method: requestOptions.method, | ||
...(requestOptions.data && { | ||
body: JSON.stringify(requestOptions.data) | ||
}), | ||
headers: { | ||
...biHeader | ||
} | ||
}); | ||
if (res.status !== 200) { | ||
var _dataError, _dataError2; | ||
let dataError = null; | ||
try { | ||
dataError = await res.json(); | ||
} catch (e) { | ||
// | ||
} | ||
throw errorBuilder(res.status, (_dataError = dataError) == null ? void 0 : _dataError.message, (_dataError2 = dataError) == null ? void 0 : _dataError2.details, { | ||
requestId: res.headers.get('X-Wix-Request-Id'), | ||
details: dataError | ||
}); | ||
} | ||
const data = await res.json(); | ||
return { | ||
data | ||
}; | ||
} catch (e) { | ||
var _e$message; | ||
if ((_e$message = e.message) != null && _e$message.includes('fetch is not defined')) { | ||
console.error('Node.js v18+ is required'); | ||
} | ||
throw e; | ||
} | ||
} | ||
}); | ||
}; | ||
const errorBuilder = (code, description, details, data) => { | ||
return { | ||
response: { | ||
data: { | ||
details: { | ||
...(!(details != null && details.validationError) && { | ||
applicationError: { | ||
description, | ||
code, | ||
data | ||
} | ||
}), | ||
...details | ||
}, | ||
message: description | ||
}, | ||
status: code | ||
} | ||
}; | ||
}; | ||
import { API_URL, PUBLIC_METADATA_KEY } from './common'; | ||
import { getDefaultContentHeader, isObject } from './helpers'; | ||
import { buildRESTDescriptor } from './rest-modules'; | ||
import { buildHostModule, isHostModule } from './host-modules'; | ||
/** | ||
* This type takes in a descriptors object of a certain Host (including an `unknown` host) | ||
* and returns an object with the same structure, but with all descriptors replaced with their API. | ||
* Any non-descriptor properties are removed from the returned object, including descriptors that | ||
* do not match the given host (as they will not work with the given host). | ||
*/ | ||
/** | ||
* Descriptors are objects that describe the API of a module, and the module | ||
* can either be a REST module or a host module. | ||
* This type is recursive, so it can describe nested modules. | ||
*/ | ||
/** | ||
* This type is used in `createClient` to ensure that the given host matches the host of the given descriptors. | ||
* If the host does not match, the descriptor is replaced with a host module that will throw an error when used. | ||
*/ | ||
export function createClient(config) { | ||
@@ -84,3 +34,3 @@ const _headers = config.headers || { | ||
const boundFetch = async (url, options) => { | ||
const authHeaders = await authStrategy.getAuthHeaders(); | ||
const authHeaders = await authStrategy.getAuthHeaders(config.host); | ||
const defaultContentTypeHeader = getDefaultContentHeader(options); | ||
@@ -97,16 +47,12 @@ return fetch(url, { | ||
}; | ||
const isObject = val => val && typeof val === 'object' && !Array.isArray(val); | ||
const isHostModule = val => isObject(val) && val.__type === 'host'; | ||
const traverse = obj => { | ||
return Object.entries(obj).reduce((prev, _ref) => { | ||
let [key, value] = _ref; | ||
if (isObject(value)) { | ||
if (isHostModule(value)) { | ||
prev[key] = value.create(); | ||
} else { | ||
prev[key] = traverse(value); | ||
} | ||
if (isHostModule(value)) { | ||
prev[key] = buildHostModule(value, config.host); | ||
} else if (typeof obj[key] === 'function') { | ||
var _obj$PUBLIC_METADATA_; | ||
prev[key] = wrapperBuilder(value, (_obj$PUBLIC_METADATA_ = obj[PUBLIC_METADATA_KEY]) != null ? _obj$PUBLIC_METADATA_ : {}, boundFetch); | ||
prev[key] = buildRESTDescriptor(value, (_obj$PUBLIC_METADATA_ = obj[PUBLIC_METADATA_KEY]) != null ? _obj$PUBLIC_METADATA_ : {}, boundFetch); | ||
} else if (isObject(value)) { | ||
prev[key] = traverse(value); | ||
} else { | ||
@@ -113,0 +59,0 @@ prev[key] = value; |
@@ -1,2 +0,2 @@ | ||
import { AuthenticationStrategy } from './strategy'; | ||
import { AuthenticationStrategy } from '@wix/sdk-types'; | ||
export interface IApiKeyStrategy extends AuthenticationStrategy { | ||
@@ -3,0 +3,0 @@ setSiteId(siteId?: string): void; |
import { authentication } from '@wix/identity'; | ||
import { AuthenticationStrategy } from '../strategy'; | ||
import { AuthenticationStrategy } from '@wix/sdk-types'; | ||
export interface Tokens { | ||
@@ -4,0 +4,0 @@ accessToken: AccessToken; |
@@ -0,6 +1,4 @@ | ||
import { APIMetadata } from '@wix/sdk-types'; | ||
import { PublicMetadata } from '../common'; | ||
export declare const WixBIHeaderName = "x-wix-bi-gateway"; | ||
export type WixBIHeader = { | ||
[WixBIHeaderName]: WixBIHeaderValues; | ||
}; | ||
export type WixBIHeaderValues = { | ||
@@ -12,5 +10,5 @@ ['environment']: 'js-sdk'; | ||
}; | ||
export declare function biHeaderGenerator(requestOptions: any, publicMetadata: PublicMetadata): { | ||
export declare function biHeaderGenerator(apiMetadata: APIMetadata, publicMetadata?: PublicMetadata): { | ||
[WixBIHeaderName]: string; | ||
}; | ||
//# sourceMappingURL=biHeaderGenerator.d.ts.map |
export declare const getDefaultContentHeader: (options: RequestInit | undefined) => { | ||
'Content-Type'?: string; | ||
}; | ||
export declare const isObject: (val: any) => val is Object; | ||
//# sourceMappingURL=helpers.d.ts.map |
@@ -6,3 +6,3 @@ export * from './wixClient'; | ||
export * from './auth/ApiKeyAuthStrategy'; | ||
export type { AuthenticationStrategy } from './auth/strategy'; | ||
export type { AuthenticationStrategy } from '@wix/sdk-types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,25 +0,43 @@ | ||
import { Simplify } from 'type-fest'; | ||
import { AuthenticationStrategy } from './auth/strategy'; | ||
import { AuthenticationStrategy, BuildRESTFunction, HostModule, HostModuleAPI, RESTFunctionDescriptor } from '@wix/sdk-types'; | ||
import { Simplify, ConditionalExcept, EmptyObject } from 'type-fest'; | ||
import { PublicMetadata } from './common'; | ||
type Headers = { | ||
Authorization: string; | ||
} & Record<string, string>; | ||
export type HostModule<T> = { | ||
__type: 'host'; | ||
create(): T; | ||
auth(): AuthenticationStrategy; | ||
/** | ||
* This type takes in a descriptors object of a certain Host (including an `unknown` host) | ||
* and returns an object with the same structure, but with all descriptors replaced with their API. | ||
* Any non-descriptor properties are removed from the returned object, including descriptors that | ||
* do not match the given host (as they will not work with the given host). | ||
*/ | ||
type BuildDescriptors<T extends Descriptors<any>> = ConditionalExcept<{ | ||
[Key in keyof T]: T[Key] extends HostModule<any, any> ? HostModuleAPI<T[Key]> : T[Key] extends RESTFunctionDescriptor ? BuildRESTFunction<T[Key]> : T[Key] extends Descriptors<any> ? Simplify<BuildDescriptors<T[Key]>> : never; | ||
}, EmptyObject>; | ||
/** | ||
* Descriptors are objects that describe the API of a module, and the module | ||
* can either be a REST module or a host module. | ||
* This type is recursive, so it can describe nested modules. | ||
*/ | ||
export type Descriptors<Host> = RESTFunctionDescriptor | HostModule<any, Host> | { | ||
[key: string]: Descriptors<Host> | PublicMetadata | any; | ||
}; | ||
type WithoutFunctionWrapper<T> = { | ||
[Key in keyof T]: T[Key] extends HostModule<infer U> ? U : T[Key] extends (...args: any) => any ? ReturnType<T[Key]> : Simplify<WithoutFunctionWrapper<T[Key]>>; | ||
/** | ||
* This type is used in `createClient` to ensure that the given host matches the host of the given descriptors. | ||
* If the host does not match, the descriptor is replaced with a host module that will throw an error when used. | ||
*/ | ||
type AssertHostMatches<T extends Descriptors<any>, Host> = T extends HostModule<any, infer U> ? Host extends U ? T : HostModule<any, Host> : { | ||
[Key in keyof T]: T[Key] extends Descriptors<any> ? AssertHostMatches<T[Key], Host> : T[Key]; | ||
}; | ||
export interface IWrapper<Z extends AuthenticationStrategy> { | ||
export type WixClient<T extends Descriptors<Host> = Descriptors<unknown>, Z extends AuthenticationStrategy<Host> = AuthenticationStrategy<unknown>, Host = unknown> = { | ||
setHeaders(headers: Headers): void; | ||
auth: Z; | ||
fetch(relativeUrl: string, options: RequestInit): Promise<Response>; | ||
} | ||
export declare function createClient<T = any, Z extends AuthenticationStrategy = any>(config: { | ||
modules?: T; | ||
} & BuildDescriptors<T>; | ||
export declare function createClient<T extends Descriptors<Host> = Descriptors<unknown>, Z extends AuthenticationStrategy<Host> = AuthenticationStrategy<unknown>, Host = unknown>(config: { | ||
modules?: AssertHostMatches<T, Host>; | ||
auth?: Z; | ||
headers?: Headers; | ||
}): WithoutFunctionWrapper<T> & IWrapper<Z>; | ||
host?: Host; | ||
}): WixClient<T, Z, Host>; | ||
export {}; | ||
//# sourceMappingURL=wixClient.d.ts.map |
{ | ||
"name": "@wix/api-client", | ||
"version": "1.1.76", | ||
"version": "1.2.0", | ||
"license": "UNLICENSED", | ||
@@ -22,5 +22,4 @@ "author": { | ||
"build": "yoshi-library build", | ||
"start": "yoshi-library start", | ||
"test": "yoshi-library test", | ||
"test:watch": "yoshi-library test --watch", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"lint": "yoshi-library lint", | ||
@@ -33,30 +32,28 @@ "lint:fix": "yoshi-library lint --fix" | ||
"dependencies": { | ||
"@babel/runtime": "^7.22.0", | ||
"@babel/runtime": "^7.22.5", | ||
"@types/grecaptcha": "^3.0.4", | ||
"@wix/identity": "^1.0.39", | ||
"@wix/identity": "^1.0.40", | ||
"@wix/image-kit": "^1.31.0", | ||
"@wix/redirects": "^1.0.16", | ||
"@wix/sdk-types": "1.1.76", | ||
"@wix/redirects": "^1.0.19", | ||
"@wix/sdk-types": "1.2.0", | ||
"pkce-challenge": "^3.1.0", | ||
"querystring": "^0.2.1", | ||
"type-fest": "^2.19.0" | ||
"type-fest": "^3.12.0" | ||
}, | ||
"devDependencies": { | ||
"@swc/core": "^1.3.67", | ||
"@swc/jest": "^0.2.26", | ||
"@types/jest": "^27.5.2", | ||
"@types/node": "^16.18.34", | ||
"@wix/ecom": "^1.0.189", | ||
"@wix/events": "^1.0.95", | ||
"@wix/jest-yoshi-preset": "^6.60.2", | ||
"@wix/motion": "^1.0.23", | ||
"@wix/yoshi-flow-library": "^6.60.2", | ||
"@types/node": "^16.18.38", | ||
"@wix/ecom": "^1.0.238", | ||
"@wix/events": "^1.0.103", | ||
"@wix/jest-yoshi-preset": "^6.62.1", | ||
"@wix/motion": "^1.0.25", | ||
"@wix/yoshi-flow-library": "^6.62.1", | ||
"is-ci": "^3.0.1", | ||
"jest": "^27.5.1", | ||
"jest-teamcity": "^1.11.0", | ||
"ts-jest": "^27.1.5", | ||
"typescript": "~4.9.5" | ||
}, | ||
"jest": { | ||
"preset": "@wix/jest-yoshi-preset", | ||
"collectCoverage": true, | ||
"coverageReporters": [ | ||
"html" | ||
] | ||
}, | ||
"yoshiFlowLibrary": { | ||
@@ -82,3 +79,3 @@ "buildEsmWithBabel": true | ||
}, | ||
"falconPackageHash": "0c0e8cfbe2c9989875b61b15fecef2be02566ad3e2da3bc278b8e7e0" | ||
"falconPackageHash": "1ed3f9da9309d3a7233e244cf78db6286df7f451ccd3a16c7ae1d279" | ||
} |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
605639
142
4886
14
+ Added@wix/sdk-types@1.2.0(transitive)
+ Addedtype-fest@3.13.1(transitive)
- Removed@wix/sdk-types@1.1.76(transitive)
- Removedtype-fest@2.19.0(transitive)
Updated@babel/runtime@^7.22.5
Updated@wix/identity@^1.0.40
Updated@wix/redirects@^1.0.19
Updated@wix/sdk-types@1.2.0
Updatedtype-fest@^3.12.0