npm package diff
Package: @forge/cli-shared
Versions: 5.4.0-next.1-experimental-264fa0f - 5.4.0-next.4
File: package/out/ari/ari.js
Index: package/out/ari/ari.js
===================================================================
--- package/out/ari/ari.js
+++ package/out/ari/ari.js
@@ -1,17 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-exports.encodeContext = exports.buildExtensionAri = exports.buildContextAri = exports.appIdToAriString = void 0;
+exports.parseInstallationContext = exports.UnknownBBWorkspaceWithoutResourceIdError = exports.UnknownWorkspaceWithoutCloudIdError = exports.UnknownSiteWithoutResourceIdError = exports.encodeContext = exports.buildExtensionAri = exports.buildContextAri = exports.appIdToAriString = exports.BITBUCKET_RESOURCE_OWNER = exports.TRELLO_RESOURCE_OWNER = exports.WORKSPACE_RESOURCE_TYPE = exports.SITE_RESOURCE_TYPE = void 0;
const ari_1 = require("@forge/util/packages/ari");
const shared_1 = require("../shared");
+const ui_1 = require("../ui");
+exports.SITE_RESOURCE_TYPE = 'site';
+exports.WORKSPACE_RESOURCE_TYPE = 'workspace';
+exports.TRELLO_RESOURCE_OWNER = 'trello';
+exports.BITBUCKET_RESOURCE_OWNER = 'bitbucket';
function appIdToAriString(appId) {
return `ari:cloud:ecosystem::app/${appId}`;
}
exports.appIdToAriString = appIdToAriString;
function buildContextAri(cloudId, product) {
return ari_1.AnyAri.create({
resourceOwner: (0, shared_1.ariResourceOwner)(product),
- resourceType: 'site',
+ resourceType: exports.SITE_RESOURCE_TYPE,
resourceId: cloudId
});
}
exports.buildContextAri = buildContextAri;
@@ -27,4 +32,50 @@
const serialised = JSON.stringify({ ctx: context.toString(), ext: extension.toString() });
return Buffer.from(serialised, 'utf-8').toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
}
exports.encodeContext = encodeContext;
+class UnknownSiteWithoutResourceIdError extends Error {
+ constructor() {
+ super(ui_1.Text.installList.noResourceId);
+ }
+}
+exports.UnknownSiteWithoutResourceIdError = UnknownSiteWithoutResourceIdError;
+class UnknownWorkspaceWithoutCloudIdError extends Error {
+ constructor() {
+ super(ui_1.Text.installList.noCloudId);
+ }
+}
+exports.UnknownWorkspaceWithoutCloudIdError = UnknownWorkspaceWithoutCloudIdError;
+class UnknownBBWorkspaceWithoutResourceIdError extends Error {
+ constructor() {
+ super(ui_1.Text.installList.bbNoResourceId);
+ }
+}
+exports.UnknownBBWorkspaceWithoutResourceIdError = UnknownBBWorkspaceWithoutResourceIdError;
+function parseInstallationContext(installationContext) {
+ const context = ari_1.AnyAri.parse(installationContext);
+ switch (context.resourceType) {
+ case exports.SITE_RESOURCE_TYPE:
+ if (!context.resourceId) {
+ throw new UnknownSiteWithoutResourceIdError();
+ }
+ context.derivedCloudId = context.resourceId;
+ break;
+ case exports.WORKSPACE_RESOURCE_TYPE:
+ if (context.resourceOwner === exports.BITBUCKET_RESOURCE_OWNER) {
+ if (!context.resourceId) {
+ throw new UnknownBBWorkspaceWithoutResourceIdError();
+ }
+ context.derivedCloudId = context.resourceId;
+ break;
+ }
+ else if (!context.cloudId) {
+ throw new UnknownWorkspaceWithoutCloudIdError();
+ }
+ context.derivedCloudId = context.cloudId;
+ break;
+ default:
+ throw new Error('Unknown resource type');
+ }
+ return context;
+}
+exports.parseInstallationContext = parseInstallationContext;