@wix/api-client
Advanced tools
Comparing version 1.10.2 to 1.11.0
@@ -1,31 +0,5 @@ | ||
import type { HttpClient as SDKHttpClient } from '@wix/sdk-types'; | ||
import type { HttpClient as SDKHttpClient, AmbassadorFactory } from '@wix/sdk-types'; | ||
import { RESTModuleOptions } from './rest-modules.js'; | ||
export type RequestContext = { | ||
isSSR: boolean; | ||
host: string; | ||
protocol?: string; | ||
}; | ||
/** | ||
* Ambassador request options types are copied mostly from AxiosRequestConfig. | ||
* They are copied and not imported to reduce the amount of dependencies (to reduce install time). | ||
* https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315 | ||
*/ | ||
export type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK'; | ||
type ResponseTransformer = (data: any, headers?: any) => any; | ||
export type AmbassadorRequestOptions<T = any> = { | ||
_?: T; | ||
url?: string; | ||
method?: Method; | ||
params?: any; | ||
data?: any; | ||
transformResponse?: ResponseTransformer | ResponseTransformer[]; | ||
}; | ||
export type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & { | ||
__isAmbassador: boolean; | ||
}; | ||
export type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>; | ||
export type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never; | ||
export declare const toHTTPModule: <Request_1, Response_1>(factory: AmbassadorFactory<Request_1, Response_1>) => (httpClient: SDKHttpClient) => (payload: Request_1) => Promise<Response_1>; | ||
export declare const ambassadorModuleOptions: () => RESTModuleOptions; | ||
export declare const isAmbassadorModule: (module: any) => boolean; | ||
export {}; |
@@ -1,3 +0,2 @@ | ||
import { APIMetadata } from '@wix/sdk-types'; | ||
import { PublicMetadata } from '../common.js'; | ||
import { APIMetadata, PublicMetadata } from '@wix/sdk-types'; | ||
export declare const WixBIHeaderName = "x-wix-bi-gateway"; | ||
@@ -4,0 +3,0 @@ export type WixBIHeaderValues = { |
export declare const PUBLIC_METADATA_KEY = "__metadata"; | ||
export type PublicMetadata = { | ||
PACKAGE_NAME?: string; | ||
}; | ||
export declare const API_URL = "www.wixapis.com"; | ||
export declare const READ_ONLY_API_URL = "readonly.wixapis.com"; | ||
export declare const FORCE_WRITE_API_URLS: string[]; |
@@ -1,3 +0,2 @@ | ||
import { PublicMetadata } from './common.js'; | ||
import { BuildRESTFunction, RESTFunctionDescriptor } from '@wix/sdk-types'; | ||
import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/sdk-types'; | ||
export type RESTModuleOptions = { | ||
@@ -4,0 +3,0 @@ HTTPHost?: string; |
import { biHeaderGenerator } from './bi/biHeaderGenerator.js'; | ||
import { API_URL, FORCE_WRITE_API_URLS, READ_ONLY_API_URL, } from './common.js'; | ||
import { API_URL, FORCE_WRITE_API_URLS, READ_ONLY_API_URL } from './common.js'; | ||
export const getDefaultDomain = (method, url) => method === 'GET' && | ||
@@ -4,0 +4,0 @@ !FORCE_WRITE_API_URLS.some((write_url) => url === write_url) |
@@ -5,4 +5,11 @@ import { BuildDescriptors, Descriptors, Host } from './index.js'; | ||
}; | ||
/** | ||
* Sets the Wix context globally. | ||
* @param wixContext The Wix context to set globally. | ||
* @param options Options for setting the context. | ||
* @param options.dangerouslyOverride If true, the context will be set even if it already exists. | ||
* @deprecated Use `WixClient.enableContext` instead. | ||
*/ | ||
export declare function setGlobalWixContext(wixContext: WixContext, options?: { | ||
dangerouslyOverride?: boolean; | ||
}): void; |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Sets the Wix context globally. | ||
* @param wixContext The Wix context to set globally. | ||
* @param options Options for setting the context. | ||
* @param options.dangerouslyOverride If true, the context will be set even if it already exists. | ||
* @deprecated Use `WixClient.enableContext` instead. | ||
*/ | ||
export function setGlobalWixContext(wixContext, options = {}) { | ||
@@ -2,0 +9,0 @@ if (!globalThis.__wix_context__ || options.dangerouslyOverride) { |
@@ -1,40 +0,7 @@ | ||
import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildEventDefinition, BuildRESTFunction, EventDefinition, EventIdentity, Host, HostModule, HostModuleAPI, RESTFunctionDescriptor, ServicePluginDefinition, BuildServicePluginDefinition, ServicePluginContract } from '@wix/sdk-types'; | ||
import { ConditionalExcept } from 'type-fest/source/conditional-except.js'; | ||
import { AuthenticationStrategy, BoundAuthenticationStrategy, BuildDescriptors, Descriptors, EventDefinition, EventIdentity, Host, HostModule, RESTFunctionDescriptor, ServicePluginContract, ServicePluginDefinition } from '@wix/sdk-types'; | ||
import { EmptyObject } from 'type-fest/source/empty-object.js'; | ||
import { AmbassadorFunctionDescriptor, BuildAmbassadorFunction } from './ambassador-modules.js'; | ||
import { PublicMetadata } from './common.js'; | ||
import type { GraphQLFormattedError } from 'graphql'; | ||
export type ContextType = 'global' | 'module'; | ||
type Headers = Record<string, string>; | ||
declare const SPI_ERROR_TYPE = "wix_spi_error"; | ||
/** | ||
* 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). | ||
*/ | ||
export type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = { | ||
done: T; | ||
recurse: T extends { | ||
__type: typeof SPI_ERROR_TYPE; | ||
} ? never : T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition ? BuildEventDefinition<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{ | ||
[Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [ | ||
-1, | ||
0, | ||
1, | ||
2, | ||
3, | ||
4, | ||
5 | ||
][Depth]> : never; | ||
}, EmptyObject>; | ||
}[Depth extends -1 ? 'done' : 'recurse']; | ||
/** | ||
* 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 = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | { | ||
[key: string]: Descriptors | PublicMetadata | any; | ||
}; | ||
/** | ||
* This type is used in `createClient` to ensure that the given host matches the host of the given descriptors. | ||
@@ -69,2 +36,3 @@ * If the host does not match, the descriptor is replaced with a host module that will throw an error when used. | ||
use<R extends Descriptors = EmptyObject>(modules: H extends Host<any> ? AssertHostMatches<R, H> : R): BuildDescriptors<R, H>; | ||
enableContext(contextType: ContextType): void; | ||
graphql<Result, Variables>(query: string | ((string | String) & TypedQueryInput<Result, Variables>), variables?: Variables): Promise<{ | ||
@@ -71,0 +39,0 @@ data: Result; |
@@ -1,2 +0,3 @@ | ||
import { EventDefinition, } from '@wix/sdk-types'; | ||
import { wixContext } from '@wix/sdk-context'; | ||
import { EventDefinition, SERVICE_PLUGIN_ERROR_TYPE, } from '@wix/sdk-types'; | ||
import { ambassadorModuleOptions, isAmbassadorModule, toHTTPModule, } from './ambassador-modules.js'; | ||
@@ -10,3 +11,2 @@ import { API_URL, PUBLIC_METADATA_KEY } from './common.js'; | ||
import { buildServicePluginDefinition, isServicePluginModule, } from './service-plugin-modules.js'; | ||
const SPI_ERROR_TYPE = 'wix_spi_error'; | ||
export function createClient(config) { | ||
@@ -60,3 +60,3 @@ const _headers = config.headers || { Authorization: '' }; | ||
// error classes using a static field that exists on them. | ||
if ('__type' in modules && modules.__type === SPI_ERROR_TYPE) { | ||
if ('__type' in modules && modules.__type === SERVICE_PLUGIN_ERROR_TYPE) { | ||
return modules; | ||
@@ -100,2 +100,15 @@ } | ||
use, | ||
enableContext(contextType) { | ||
if (contextType === 'global') { | ||
if (globalThis.__wix_context__ != null) { | ||
globalThis.__wix_context__.client = this; | ||
} | ||
else { | ||
globalThis.__wix_context__ = { client: this }; | ||
} | ||
} | ||
else { | ||
wixContext.client = this; | ||
} | ||
}, | ||
fetch: (relativeUrl, options) => { | ||
@@ -102,0 +115,0 @@ const finalUrl = new URL(relativeUrl, `https://${API_URL}`); |
{ | ||
"name": "@wix/api-client", | ||
"version": "1.10.2", | ||
"version": "1.11.0", | ||
"license": "UNLICENSED", | ||
@@ -25,5 +25,7 @@ "main": "build/index.js", | ||
"@wix/identity": "^1.0.78", | ||
"@wix/image-kit": "^1.69.0", | ||
"@wix/image-kit": "^1.70.0", | ||
"@wix/redirects": "^1.0.41", | ||
"@wix/sdk-types": "^1.8.0", | ||
"@wix/sdk-context": "^0.0.1", | ||
"@wix/sdk-runtime": "0.3.0", | ||
"@wix/sdk-types": "^1.9.0", | ||
"crypto-js": "^4.2.0", | ||
@@ -37,3 +39,3 @@ "jose": "^5.2.1", | ||
"@wix/metro-runtime": "^1.1677.0", | ||
"@wix/sdk": "1.10.2" | ||
"@wix/sdk": "1.11.0" | ||
}, | ||
@@ -51,3 +53,3 @@ "wix": { | ||
}, | ||
"falconPackageHash": "5255eaa26d485f44b79cdb972a5c5beafaf5354ba31fd4fe6f21e011" | ||
"falconPackageHash": "bad997f56f5c8193d825bb9e8889b6ff02900da47b127db9c0220c6a" | ||
} |
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
48
79128
12
1948
+ Added@wix/sdk-context@^0.0.1
+ Added@wix/sdk-runtime@0.3.0
+ Added@wix/sdk-runtime@0.3.0(transitive)
Updated@wix/image-kit@^1.70.0
Updated@wix/sdk-types@^1.9.0