Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@forge/bridge

Package Overview
Dependencies
Maintainers
0
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@forge/bridge - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1-next.0

6

CHANGELOG.md
# @forge/bridge
## 4.0.1-next.0
### Patch Changes
- 04ef35e: Upgrade target to ES2018
## 4.0.0

@@ -4,0 +10,0 @@

29

out/fetch/fetch.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.productFetchApi = void 0;
const tslib_1 = require("tslib");
const blobParser_1 = require("../utils/blobParser");
const parseFormData = (form) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const parseFormData = async (form) => {
const parsed = {};

@@ -12,3 +11,3 @@ for (const [key, value] of form.entries()) {

const fileType = value.type;
parsed['file'] = yield (0, blobParser_1.blobToBase64)(value);
parsed['file'] = await (0, blobParser_1.blobToBase64)(value);
parsed['__fileName'] = fileName;

@@ -22,9 +21,9 @@ parsed['__fileType'] = fileType;

return JSON.stringify(parsed);
});
const parseRequest = (init) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
};
const parseRequest = async (init) => {
const isFormData = (init === null || init === void 0 ? void 0 : init.body) instanceof FormData ? true : false;
const requestBody = isFormData ? yield parseFormData(init === null || init === void 0 ? void 0 : init.body) : init === null || init === void 0 ? void 0 : init.body;
const requestBody = isFormData ? await parseFormData(init === null || init === void 0 ? void 0 : init.body) : init === null || init === void 0 ? void 0 : init.body;
const req = new Request('', { body: requestBody, method: init === null || init === void 0 ? void 0 : init.method, headers: init === null || init === void 0 ? void 0 : init.headers });
const headers = Object.fromEntries(req.headers.entries());
const body = req.method !== 'GET' ? yield req.text() : null;
const body = req.method !== 'GET' ? await req.text() : null;
return {

@@ -35,6 +34,6 @@ body,

};
});
};
const productFetchApi = (callBridge) => {
const fetch = (product, restPath, init) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const { body: requestBody, headers: requestHeaders, isMultipartFormData } = yield parseRequest(init);
const fetch = async (product, restPath, init) => {
const { body: requestBody, headers: requestHeaders, isMultipartFormData } = await parseRequest(init);
if (!requestHeaders.has('X-Atlassian-Token')) {

@@ -46,9 +45,13 @@ requestHeaders.set('X-Atlassian-Token', 'no-check');

restPath,
fetchRequestInit: Object.assign(Object.assign({}, init), { body: requestBody, headers: [...requestHeaders.entries()] }),
fetchRequestInit: {
...init,
body: requestBody,
headers: [...requestHeaders.entries()]
},
isMultipartFormData
};
const { body, headers, statusText, status, isAttachment } = yield callBridge('fetchProduct', fetchPayload);
const { body, headers, statusText, status, isAttachment } = await callBridge('fetchProduct', fetchPayload);
const responseBody = isAttachment ? (0, blobParser_1.base64ToBlob)(body, headers['content-type']) : body;
return new Response(responseBody || null, { headers, status, statusText });
});
};
return {

@@ -55,0 +58,0 @@ requestConfluence: (restPath, fetchOptions) => fetch('confluence', restPath, fetchOptions),

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.showFlag = void 0;
const tslib_1 = require("tslib");
const bridge_1 = require("../bridge");

@@ -13,10 +12,13 @@ const errors_1 = require("../errors");

}
const result = callBridge('showFlag', Object.assign(Object.assign({}, options), { type: (_a = options.type) !== null && _a !== void 0 ? _a : 'info' }));
const result = callBridge('showFlag', {
...options,
type: (_a = options.type) !== null && _a !== void 0 ? _a : 'info'
});
return {
close: () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
yield result;
close: async () => {
await result;
return callBridge('closeFlag', { id: options.id });
})
}
};
};
exports.showFlag = showFlag;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTranslationFunction = exports.getTranslations = exports.resetTranslationsCache = void 0;
const tslib_1 = require("tslib");
const i18n_1 = require("@forge/i18n");
const view_1 = require("../view");
const frontendResourcesAccessor = {
getI18nInfoConfig: () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const resp = yield fetch(`./${i18n_1.I18N_BUNDLE_FOLDER_NAME}/${i18n_1.I18N_INFO_FILE_NAME}`);
getI18nInfoConfig: async () => {
const resp = await fetch(`./${i18n_1.I18N_BUNDLE_FOLDER_NAME}/${i18n_1.I18N_INFO_FILE_NAME}`);
if (!resp.ok) {
throw new Error('Failed to get i18n info config: ' + resp.statusText);
}
const info = (yield resp.json());
const info = (await resp.json());
return info.config;
}),
getTranslationResource: (locale) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const resp = yield fetch(`./${i18n_1.I18N_BUNDLE_FOLDER_NAME}/${locale}.json`);
},
getTranslationResource: async (locale) => {
const resp = await fetch(`./${i18n_1.I18N_BUNDLE_FOLDER_NAME}/${locale}.json`);
if (!resp.ok) {

@@ -22,3 +21,3 @@ throw new Error(`Failed to get translation resource for locale: ${locale}`);

return resp.json();
})
}
};

@@ -30,23 +29,23 @@ const translationsGetter = new i18n_1.TranslationsGetter(frontendResourcesAccessor);

exports.resetTranslationsCache = resetTranslationsCache;
const getTranslations = (locale = null, options = {
const getTranslations = async (locale = null, options = {
fallback: true
}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
}) => {
let targetLocale = locale;
if (!targetLocale) {
const context = yield view_1.view.getContext();
const context = await view_1.view.getContext();
targetLocale = context.locale;
}
return yield translationsGetter.getTranslations(targetLocale, options);
});
return await translationsGetter.getTranslations(targetLocale, options);
};
exports.getTranslations = getTranslations;
const createTranslationFunction = (locale = null) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const createTranslationFunction = async (locale = null) => {
let targetLocale = locale;
if (!targetLocale) {
const context = yield view_1.view.getContext();
const context = await view_1.view.getContext();
targetLocale = context.locale;
}
const translator = new i18n_1.Translator(targetLocale, translationsGetter);
yield translator.init();
await translator.init();
return (i18nKey, defaultValue) => { var _a, _b; return (_b = (_a = translator.translate(i18nKey)) !== null && _a !== void 0 ? _a : defaultValue) !== null && _b !== void 0 ? _b : i18nKey; };
});
};
exports.createTranslationFunction = createTranslationFunction;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.invokeRemote = void 0;
const tslib_1 = require("tslib");
const bridge_1 = require("../bridge");

@@ -18,7 +17,7 @@ const errors_1 = require("../errors");

};
const _invokeRemote = (input) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const _invokeRemote = async (input) => {
var _a;
validatePayload(input);
const { success, payload, error } = (_a = (yield callBridge('invoke', input))) !== null && _a !== void 0 ? _a : {};
const response = Object.assign({}, (success ? payload : error));
const { success, payload, error } = (_a = (await callBridge('invoke', input))) !== null && _a !== void 0 ? _a : {};
const response = { ...(success ? payload : error) };
if (response && response.headers) {

@@ -32,3 +31,3 @@ for (const header in response.headers) {

return response;
});
};
exports.invokeRemote = (0, utils_1.withRateLimiter)(_invokeRemote, MAX_NUM_OPERATIONS, OPERATION_INTERVAL_MS, 'Remote invocation calls are rate limited at 500req/25s');
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Modal = void 0;
const tslib_1 = require("tslib");
const bridge_1 = require("../bridge");

@@ -19,23 +18,21 @@ const errors_1 = require("../errors");

}
open() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const success = yield callBridge('openModal', {
resource: this.resource,
onClose: this.onClose,
size: this.size,
context: this.context,
closeOnEscape: this.closeOnEscape,
closeOnOverlayClick: this.closeOnOverlayClick
});
if (success === false) {
throw new errors_1.BridgeAPIError('Unable to open modal.');
}
}
catch (err) {
async open() {
try {
const success = await callBridge('openModal', {
resource: this.resource,
onClose: this.onClose,
size: this.size,
context: this.context,
closeOnEscape: this.closeOnEscape,
closeOnOverlayClick: this.closeOnOverlayClick
});
if (success === false) {
throw new errors_1.BridgeAPIError('Unable to open modal.');
}
});
}
catch (err) {
throw new errors_1.BridgeAPIError('Unable to open modal.');
}
}
}
exports.Modal = Modal;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.router = void 0;
const tslib_1 = require("tslib");
const bridge_1 = require("../bridge");
const callBridge = (0, bridge_1.getCallBridge)();
const navigate = (url) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return callBridge('navigate', { url, type: 'same-tab' }); });
const open = (url) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return callBridge('navigate', { url, type: 'new-tab' }); });
const reload = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return callBridge('reload'); });
const navigate = async (url) => callBridge('navigate', { url, type: 'same-tab' });
const open = async (url) => callBridge('navigate', { url, type: 'new-tab' });
const reload = async () => callBridge('reload');
exports.router = {

@@ -11,0 +10,0 @@ navigate,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withRateLimiter = void 0;
const tslib_1 = require("tslib");
const errors_1 = require("../errors");

@@ -9,3 +8,3 @@ const withRateLimiter = (wrappedFn, maxOps, intervalInMs, exceededErrorMessage) => {

let numOps = 0;
return (...args) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
return async (...args) => {
const now = Date.now();

@@ -22,4 +21,4 @@ const elapsed = now - start;

return wrappedFn(...args);
});
};
};
exports.withRateLimiter = withRateLimiter;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.close = void 0;
const tslib_1 = require("tslib");
const bridge_1 = require("../bridge");
const errors_1 = require("../errors");
const callBridge = (0, bridge_1.getCallBridge)();
const close = (payload) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const close = async (payload) => {
try {
const success = yield callBridge('close', payload);
const success = await callBridge('close', payload);
if (success === false) {

@@ -18,3 +17,3 @@ throw new errors_1.BridgeAPIError("this resource's view is not closable.");

}
});
};
exports.close = close;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHistory = void 0;
const tslib_1 = require("tslib");
const bridge_1 = require("../bridge");
const callBridge = (0, bridge_1.getCallBridge)();
const createHistory = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const history = yield callBridge('createHistory');
const createHistory = async () => {
const history = await callBridge('createHistory');
history.listen((location) => {

@@ -13,3 +12,3 @@ history.location = location;

return history;
});
};
exports.createHistory = createHistory;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.frame = void 0;
const tslib_1 = require("tslib");
const internal_1 = require("../internal");

@@ -10,4 +9,4 @@ const events_1 = require("../events");

const EVENT_KEY_FRAME_LOADED = 'loaded';
const onPropsUpdate = (handler) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const frameId = yield (0, internal_1.getFrameId)();
const onPropsUpdate = async (handler) => {
const frameId = await (0, internal_1.getFrameId)();
if (!frameId) {

@@ -17,11 +16,11 @@ throw new Error('Frame could not be found, please ensure the custom props enabled Frame component is set up correctly.');

const sub = events_1.events.on(frameEventKey(EVENT_KEY_FRAME_PROPS, frameId), handler);
const unsubscribe = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const subscription = yield sub;
const unsubscribe = async () => {
const subscription = await sub;
subscription.unsubscribe();
});
};
void events_1.events.emit(frameEventKey(EVENT_KEY_FRAME_LOADED, frameId), { loaded: true });
return unsubscribe;
});
};
exports.frame = {
onPropsUpdate
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getContext = void 0;
const tslib_1 = require("tslib");
const bridge_1 = require("../bridge");
const i18n_1 = require("@forge/i18n");
const callBridge = (0, bridge_1.getCallBridge)();
const getContext = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const getContext = async () => {
var _a;
const context = yield callBridge('getContext');
const context = await callBridge('getContext');
const locale = context === null || context === void 0 ? void 0 : context.locale;

@@ -16,3 +15,3 @@ if (locale) {

return context;
});
};
exports.getContext = getContext;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.refresh = void 0;
const tslib_1 = require("tslib");
const bridge_1 = require("../bridge");
const errors_1 = require("../errors");
const callBridge = (0, bridge_1.getCallBridge)();
const refresh = (payload) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const success = yield callBridge('refresh', payload);
const refresh = async (payload) => {
const success = await callBridge('refresh', payload);
if (success === false) {
throw new errors_1.BridgeAPIError("this resource's view is not refreshable.");
}
});
};
exports.refresh = refresh;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.submit = void 0;
const tslib_1 = require("tslib");
const bridge_1 = require("../bridge");
const errors_1 = require("../errors");
const callBridge = (0, bridge_1.getCallBridge)();
const submit = (payload) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const success = yield callBridge('submit', payload);
const submit = async (payload) => {
const success = await callBridge('submit', payload);
if (success === false) {
throw new errors_1.BridgeAPIError("this resource's view is not submittable.");
}
});
};
exports.submit = submit;
{
"name": "@forge/bridge",
"version": "4.0.0",
"version": "4.0.1-next.0",
"description": "Forge bridge API for custom UI apps",

@@ -5,0 +5,0 @@ "author": "Atlassian",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc