@wix/sdk-runtime
Advanced tools
Comparing version 0.3.9 to 0.3.10
@@ -27,3 +27,10 @@ import { wixContext } from '@wix/sdk-context'; | ||
: undefined; | ||
if (!contextualClient) { | ||
const elevatedClient = typeof $wixContext !== 'undefined' | ||
? $wixContext.elevatedClient | ||
: typeof wixContext.elevatedClient !== 'undefined' | ||
? wixContext.elevatedClient | ||
: typeof globalThis.__wix_context__ !== 'undefined' | ||
? globalThis.__wix_context__.elevatedClient | ||
: undefined; | ||
if (!contextualClient && !elevatedClient) { | ||
return; | ||
@@ -34,20 +41,22 @@ } | ||
if (elevated) { | ||
const elevatedClient = typeof $wixContext !== 'undefined' | ||
? $wixContext.elevatedClient | ||
: typeof wixContext.elevatedClient !== 'undefined' | ||
? wixContext.elevatedClient | ||
: typeof globalThis.__wix_context__ !== 'undefined' | ||
? globalThis.__wix_context__.elevatedClient | ||
: undefined; | ||
if (!elevatedClient) { | ||
throw new Error('An elevated client is required to use elevated modules. Make sure to initialize the Wix context with an elevated client before using elevated SDK modules'); | ||
} | ||
return elevatedClient.use(wixModules); | ||
return runWithoutContext(() => elevatedClient.use(wixModules)); | ||
} | ||
return contextualClient.use(wixModules); | ||
if (!contextualClient) { | ||
throw new Error('Wix context is not available. Make sure to initialize the Wix context before using SDK modules'); | ||
} | ||
return runWithoutContext(() => contextualClient.use(wixModules)); | ||
}, | ||
fetchWithAuth: (urlOrRequest, requestInit) => { | ||
if (!contextualClient) { | ||
throw new Error('Wix context is not available. Make sure to initialize the Wix context before using SDK modules'); | ||
} | ||
return contextualClient.fetchWithAuth(urlOrRequest, requestInit); | ||
}, | ||
async graphql(query, variables, opts) { | ||
if (!contextualClient) { | ||
throw new Error('Wix context is not available. Make sure to initialize the Wix context before using SDK modules'); | ||
} | ||
return contextualClient.graphql(query, variables, opts); | ||
@@ -96,1 +105,32 @@ }, | ||
export * from './context-v2.js'; | ||
function runWithoutContext(fn) { | ||
const globalContext = globalThis.__wix_context__; | ||
const moduleContext = { | ||
client: wixContext.client, | ||
elevatedClient: wixContext.elevatedClient, | ||
}; | ||
let closureContext; | ||
globalThis.__wix_context__ = undefined; | ||
wixContext.client = undefined; | ||
wixContext.elevatedClient = undefined; | ||
if (typeof $wixContext !== 'undefined') { | ||
closureContext = { | ||
client: $wixContext?.client, | ||
elevatedClient: $wixContext?.elevatedClient, | ||
}; | ||
delete $wixContext.client; | ||
delete $wixContext.elevatedClient; | ||
} | ||
try { | ||
return fn(); | ||
} | ||
finally { | ||
globalThis.__wix_context__ = globalContext; | ||
wixContext.client = moduleContext.client; | ||
wixContext.elevatedClient = moduleContext.elevatedClient; | ||
if (typeof $wixContext !== 'undefined') { | ||
$wixContext.client = closureContext.client; | ||
$wixContext.elevatedClient = closureContext.elevatedClient; | ||
} | ||
} | ||
} |
@@ -44,3 +44,10 @@ "use strict"; | ||
: undefined; | ||
if (!contextualClient) { | ||
const elevatedClient = typeof $wixContext !== 'undefined' | ||
? $wixContext.elevatedClient | ||
: typeof sdk_context_1.wixContext.elevatedClient !== 'undefined' | ||
? sdk_context_1.wixContext.elevatedClient | ||
: typeof globalThis.__wix_context__ !== 'undefined' | ||
? globalThis.__wix_context__.elevatedClient | ||
: undefined; | ||
if (!contextualClient && !elevatedClient) { | ||
return; | ||
@@ -51,20 +58,22 @@ } | ||
if (elevated) { | ||
const elevatedClient = typeof $wixContext !== 'undefined' | ||
? $wixContext.elevatedClient | ||
: typeof sdk_context_1.wixContext.elevatedClient !== 'undefined' | ||
? sdk_context_1.wixContext.elevatedClient | ||
: typeof globalThis.__wix_context__ !== 'undefined' | ||
? globalThis.__wix_context__.elevatedClient | ||
: undefined; | ||
if (!elevatedClient) { | ||
throw new Error('An elevated client is required to use elevated modules. Make sure to initialize the Wix context with an elevated client before using elevated SDK modules'); | ||
} | ||
return elevatedClient.use(wixModules); | ||
return runWithoutContext(() => elevatedClient.use(wixModules)); | ||
} | ||
return contextualClient.use(wixModules); | ||
if (!contextualClient) { | ||
throw new Error('Wix context is not available. Make sure to initialize the Wix context before using SDK modules'); | ||
} | ||
return runWithoutContext(() => contextualClient.use(wixModules)); | ||
}, | ||
fetchWithAuth: (urlOrRequest, requestInit) => { | ||
if (!contextualClient) { | ||
throw new Error('Wix context is not available. Make sure to initialize the Wix context before using SDK modules'); | ||
} | ||
return contextualClient.fetchWithAuth(urlOrRequest, requestInit); | ||
}, | ||
async graphql(query, variables, opts) { | ||
if (!contextualClient) { | ||
throw new Error('Wix context is not available. Make sure to initialize the Wix context before using SDK modules'); | ||
} | ||
return contextualClient.graphql(query, variables, opts); | ||
@@ -118,1 +127,32 @@ }, | ||
__exportStar(require("./context-v2.js"), exports); | ||
function runWithoutContext(fn) { | ||
const globalContext = globalThis.__wix_context__; | ||
const moduleContext = { | ||
client: sdk_context_1.wixContext.client, | ||
elevatedClient: sdk_context_1.wixContext.elevatedClient, | ||
}; | ||
let closureContext; | ||
globalThis.__wix_context__ = undefined; | ||
sdk_context_1.wixContext.client = undefined; | ||
sdk_context_1.wixContext.elevatedClient = undefined; | ||
if (typeof $wixContext !== 'undefined') { | ||
closureContext = { | ||
client: $wixContext?.client, | ||
elevatedClient: $wixContext?.elevatedClient, | ||
}; | ||
delete $wixContext.client; | ||
delete $wixContext.elevatedClient; | ||
} | ||
try { | ||
return fn(); | ||
} | ||
finally { | ||
globalThis.__wix_context__ = globalContext; | ||
sdk_context_1.wixContext.client = moduleContext.client; | ||
sdk_context_1.wixContext.elevatedClient = moduleContext.elevatedClient; | ||
if (typeof $wixContext !== 'undefined') { | ||
$wixContext.client = closureContext.client; | ||
$wixContext.elevatedClient = closureContext.elevatedClient; | ||
} | ||
} | ||
} |
{ | ||
"name": "@wix/sdk-runtime", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"license": "UNLICENSED", | ||
@@ -80,3 +80,3 @@ "sideEffects": false, | ||
"@wix/sdk-context": "^0.0.1", | ||
"@wix/sdk-types": "^1.9.1" | ||
"@wix/sdk-types": "^1.9.2" | ||
}, | ||
@@ -113,3 +113,3 @@ "devDependencies": { | ||
}, | ||
"falconPackageHash": "792e970b910a4a5f62db234ff9f4d5550dcc78aa8e0b77d6d46a52c5" | ||
"falconPackageHash": "bb330a1c81b02f1c8276543f0353f457f3124c66a31c3b7c4197c7c0" | ||
} |
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
170912
4327
Updated@wix/sdk-types@^1.9.2