@communities-webruntime/services
Version:
If you would like to run Lightning Web Runtime without the CLI, we expose some of our programmatic APIs available in Node.js. If you're looking for the CLI documentation [you can find that here](https://www.npmjs.com/package/@communities-webruntime/cli).
48 lines • 1.69 kB
JavaScript
/**
* Copyright (c) 2019, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import path from 'path';
import { hashContent } from '@lwrjs/shared-utils';
import { ClientService } from '../client/client-service.js';
export default class CSRFService {
constructor() {
this.name = 'csrf-provider';
this.version = '1';
this.count = 0;
}
async getModuleEntry({ specifier }) {
if (specifier === '@app/csrfToken') {
return {
// create a new module id for each request to avoid registry cache hits
id: `${specifier}/${this.count++}|${this.version}`,
virtual: true,
entry: `<virtual>/${specifier}${path.extname(specifier.replace(/\./g, '-')) ? '' : '.js'}`,
specifier,
version: this.version,
};
}
}
async getModule({ specifier, namespace, name = specifier, }) {
const moduleEntry = await this.getModuleEntry({ specifier });
if (!moduleEntry) {
return;
}
const token = ClientService.generateToken();
const originalSource = "export default '${token}'";
return {
id: moduleEntry.id,
specifier,
namespace,
name,
version: this.version,
originalSource,
moduleEntry,
ownHash: hashContent(originalSource),
compiledSource: originalSource.replace('${token}', token),
};
}
}
//# sourceMappingURL=csrf-provider.js.map