@wix/api-client
Advanced tools
Comparing version 1.1.75 to 1.1.76
@@ -225,3 +225,27 @@ "use strict"; | ||
}); | ||
describe('host modules', () => { | ||
it('should support host modules', async () => { | ||
const hostModule = { | ||
__type: 'host', | ||
create: () => ({ | ||
aHostFunction: a => Promise.resolve(a + 1) | ||
}), | ||
auth() { | ||
return { | ||
getAuthHeaders: async () => ({ | ||
headers: {} | ||
}) | ||
}; | ||
} | ||
}; | ||
const client = (0, _wixClient.createClient)({ | ||
modules: { | ||
hostModule | ||
}, | ||
auth: hostModule.auth() | ||
}); | ||
expect(client.hostModule.aHostFunction(1)).resolves.toBe(2); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=wixClient.spec.js.map |
@@ -101,6 +101,11 @@ "use strict"; | ||
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)) { | ||
prev[key] = traverse(value); | ||
if (isHostModule(value)) { | ||
prev[key] = value.create(); | ||
} else { | ||
prev[key] = traverse(value); | ||
} | ||
} else if (typeof obj[key] === 'function') { | ||
@@ -107,0 +112,0 @@ prev[key] = wrapperBuilder(value, obj[_common.PUBLIC_METADATA_KEY] ?? {}, boundFetch); |
@@ -223,3 +223,27 @@ import { cart, currentCart } from '@wix/ecom'; | ||
}); | ||
describe('host modules', () => { | ||
it('should support host modules', async () => { | ||
const hostModule = { | ||
__type: 'host', | ||
create: () => ({ | ||
aHostFunction: a => Promise.resolve(a + 1) | ||
}), | ||
auth() { | ||
return { | ||
getAuthHeaders: async () => ({ | ||
headers: {} | ||
}) | ||
}; | ||
} | ||
}; | ||
const client = createClient({ | ||
modules: { | ||
hostModule | ||
}, | ||
auth: hostModule.auth() | ||
}); | ||
expect(client.hostModule.aHostFunction(1)).resolves.toBe(2); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=wixClient.spec.js.map |
@@ -97,2 +97,3 @@ import { biHeaderGenerator } from './bi/biHeaderGenerator'; | ||
const isObject = val => val && typeof val === 'object' && !Array.isArray(val); | ||
const isHostModule = val => isObject(val) && val.__type === 'host'; | ||
const traverse = obj => { | ||
@@ -102,3 +103,7 @@ return Object.entries(obj).reduce((prev, _ref) => { | ||
if (isObject(value)) { | ||
prev[key] = traverse(value); | ||
if (isHostModule(value)) { | ||
prev[key] = value.create(); | ||
} else { | ||
prev[key] = traverse(value); | ||
} | ||
} else if (typeof obj[key] === 'function') { | ||
@@ -105,0 +110,0 @@ var _obj$PUBLIC_METADATA_; |
@@ -6,4 +6,9 @@ import { Simplify } from 'type-fest'; | ||
} & Record<string, string>; | ||
export type HostModule<T> = { | ||
__type: 'host'; | ||
create(): T; | ||
auth(): AuthenticationStrategy; | ||
}; | ||
type WithoutFunctionWrapper<T> = { | ||
[Key in keyof T]: T[Key] extends (...args: any) => any ? ReturnType<T[Key]> : Simplify<WithoutFunctionWrapper<T[Key]>>; | ||
[Key in keyof T]: T[Key] extends HostModule<infer U> ? U : T[Key] extends (...args: any) => any ? ReturnType<T[Key]> : Simplify<WithoutFunctionWrapper<T[Key]>>; | ||
}; | ||
@@ -10,0 +15,0 @@ export interface IWrapper<Z extends AuthenticationStrategy> { |
{ | ||
"name": "@wix/api-client", | ||
"version": "1.1.75", | ||
"version": "1.1.76", | ||
"license": "UNLICENSED", | ||
@@ -34,6 +34,6 @@ "author": { | ||
"@types/grecaptcha": "^3.0.4", | ||
"@wix/identity": "^1.0.38", | ||
"@wix/identity": "^1.0.39", | ||
"@wix/image-kit": "^1.31.0", | ||
"@wix/redirects": "^1.0.16", | ||
"@wix/sdk-types": "1.1.75", | ||
"@wix/sdk-types": "1.1.76", | ||
"pkce-challenge": "^3.1.0", | ||
@@ -46,7 +46,7 @@ "querystring": "^0.2.1", | ||
"@types/node": "^16.18.34", | ||
"@wix/ecom": "^1.0.183", | ||
"@wix/events": "^1.0.92", | ||
"@wix/jest-yoshi-preset": "^6.60.0", | ||
"@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.0", | ||
"@wix/yoshi-flow-library": "^6.60.2", | ||
"ts-jest": "^27.1.5", | ||
@@ -82,3 +82,3 @@ "typescript": "~4.9.5" | ||
}, | ||
"falconPackageHash": "1dac50fc01774f74ecd8111352b20b3f70a685924764eab33e638dbf" | ||
"falconPackageHash": "0c0e8cfbe2c9989875b61b15fecef2be02566ad3e2da3bc278b8e7e0" | ||
} |
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
578889
4722
+ Added@wix/sdk-types@1.1.76(transitive)
- Removed@wix/sdk-types@1.1.75(transitive)
Updated@wix/identity@^1.0.39
Updated@wix/sdk-types@1.1.76