Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
935 changes: 935 additions & 0 deletions nx/blocks/loc/connectors/globallink/index.js

Large diffs are not rendered by default.

40 changes: 39 additions & 1 deletion nx/blocks/loc/utils/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { daFetch } from '../../../../nx2/utils/api.js';
import { daFetch, loadIms, handleSignIn } from '../../../../nx2/utils/api.js';
import { DA_ETC } from '../../../../nx2/utils/utils.js';

// DA_ETC_ENVS has no 'stage' entry, so DA_ETC resolves to undefined in a
Expand Down Expand Up @@ -124,3 +124,41 @@ export default async function authReady(name, service) {
const accessToken = await getAccessToken(name, service);
return !!accessToken;
}

/**
* Checks whether an IMS session is currently available, without triggering the sign-in
* flow if not - unlike {@link imsAccessToken}, safe to call repeatedly (e.g. from inside a
* polling loop) without repeatedly invoking `handleSignIn()`.
* @returns {Promise<boolean>} Whether a usable IMS access token is available.
*/
export async function hasImsSession() {
const { accessToken } = await loadIms();
return !!accessToken;
}

/**
* Resolves the current IMS access token, mirroring how `daFetch` authenticates calls to
* DA_TRANSLATE elsewhere (e.g. the Google connector). Connectors whose DA_TRANSLATE proxy
* requires IMS auth (e.g. GlobalLink) use this instead of building their own IMS session
* handling. Triggers the sign-in flow if no IMS session is available.
* @returns {Promise<string|null>} The token, or `null` if no IMS session is available.
*/
export async function imsAccessToken() {
const { accessToken } = await loadIms();
if (!accessToken) {
handleSignIn();
return null;
}
return accessToken.token;
}

/**
* Builds the Authorization header a DA_TRANSLATE proxy requires to gate access to a
* connector's endpoint.
* @returns {Promise<{Authorization?: string}>} The header to merge into the request, or
* `{}` if no IMS token could be obtained.
*/
export async function imsAuthHeader() {
const token = await imsAccessToken();
return token ? { Authorization: `Bearer ${token}` } : {};
}
1 change: 1 addition & 0 deletions nx2/deps/fflate/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions nx2/deps/fflate/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { zipSync, unzipSync, strToU8, strFromU8 } from 'fflate';

export { zipSync, unzipSync, strToU8, strFromU8 };
8 changes: 7 additions & 1 deletion nx2/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ const DA_FEEDBACK_ENVS = {
prod: 'https://feedback.da.live/feedback',
};

const DA_TRANSLATE_ENVS = {
local: 'http://localhost:8788',
stage: 'https://translate.da.live',
prod: 'https://translate.da.live',
};

function getEnv(key, envs) {
const params = new URLSearchParams(window.location.search);
const query = params.get(key);
Expand All @@ -69,10 +75,10 @@ export const DA_CONTENT = getEnv('da-content', DA_CONTENT_ENVS);
export const DA_PREVIEW = getEnv('da-preview', DA_LIVE_PREVIEW_ENVS);
export const DA_ETC = getEnv('da-etc', DA_ETC_ENVS);
export const DA_FEEDBACK = getEnv('da-feedback', DA_FEEDBACK_ENVS);
export const DA_TRANSLATE = getEnv('da-translate', DA_TRANSLATE_ENVS);

export const HLX_ADMIN = 'https://admin.hlx.page';
export const AEM_API = 'https://api.aem.live';
export const DA_TRANSLATE = 'https://translate.da.live';

export const ALLOWED_TOKEN = [
DA_ADMIN,
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"nx2:test:file:watch": "wtr --config ./nx2/test/wtr.config.mjs --node-resolve --port=2000 --coverage --watch",
"nx2:build:da-lit": "esbuild --format=esm --minify ./nx2/deps/lit/src/index.js --bundle --outfile=./nx2/deps/lit/dist/index.js",
"nx2:build:spectrum": "node nx2/deps/spectrum/build.js",
"nx2:build:mdast": "esbuild --format=esm --minify ./nx2/deps/mdast/src/index.js --bundle --outfile=./nx2/deps/mdast/dist/index.js"
"nx2:build:mdast": "esbuild --format=esm --minify ./nx2/deps/mdast/src/index.js --bundle --outfile=./nx2/deps/mdast/dist/index.js",
"nx2:build:fflate": "esbuild --format=esm --minify ./nx2/deps/fflate/src/index.js --bundle --outfile=./nx2/deps/fflate/dist/index.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -75,6 +76,7 @@
"@lit-labs/virtualizer": "^2.0.16",
"codemirror": "^6.0.2",
"esbuild": ">=0.25.0",
"fflate": "^0.8.3",
"hast-util-raw": "^9.0.4",
"hast-util-to-dom": "^4.0.1",
"hast-util-to-html": "^9.0.3",
Expand Down
Loading
Loading