npm package diff
Package: @forge/util
Versions: 1.4.10-next.0 - 1.4.10-next.0-experimental-effab31
File: package/packages/ari/avp/chart/index.js
Index: package/packages/ari/avp/chart/index.js
===================================================================
--- package/packages/ari/avp/chart/index.js
+++ package/packages/ari/avp/chart/index.js
@@ -0,0 +1,347 @@
+"use strict";
+var __defProp = Object.defineProperty;
+var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
+var __getOwnPropNames = Object.getOwnPropertyNames;
+var __hasOwnProp = Object.prototype.hasOwnProperty;
+var __export = (target, all) => {
+ for (var name in all)
+ __defProp(target, name, { get: all[name], enumerable: !0 });
+}, __copyProps = (to, from, except, desc) => {
+ if (from && typeof from == "object" || typeof from == "function")
+ for (let key of __getOwnPropNames(from))
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
+ return to;
+};
+var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
+
+// src/avp/chart/index.ts
+var chart_exports = {};
+__export(chart_exports, {
+ AvpChartAri: () => AvpChartAri,
+ AvpChartAriResourceOwner: () => AvpChartAriResourceOwner,
+ AvpChartAriResourceType: () => AvpChartAriResourceType
+});
+module.exports = __toCommonJS(chart_exports);
+
+// src/errors.ts
+var ValidationError = class extends Error {
+};
+
+// src/core/rules/cloud-id.ts
+function validateCloudId(cloudId, format = new RegExp("^[a-zA-Z0-9_\\-.]{0,255}$")) {
+ if (!cloudId.match(format))
+ throw new ValidationError(`Invalid cloud ID, expected ID of format ${format}.`);
+}
+
+// src/core/rules/platform-qualifier.ts
+function validatePlatformQualifier(qualifier) {
+ if (qualifier !== "cloud" && qualifier !== "third-party")
+ throw new ValidationError(`Identifier must have a qualifier of 'cloud' or 'third-party'. Received: ${qualifier}`);
+}
+
+// src/core/rules/qualifier.ts
+function validateAtiQualifier(qualifier) {
+ if (qualifier !== "ati")
+ throw new ValidationError(`ATI must have a qualifier of 'ati'. Received: ${qualifier}`);
+}
+function validateAriQualifier(qualifier) {
+ if (qualifier !== "ari")
+ throw new ValidationError(`ARI must have a qualifier of 'ari'. Received: ${qualifier}`);
+}
+
+// src/core/rules/resource-id.ts
+function validateResourceId(id, format = new RegExp("[!a-zA-Z0-9\\-_.~@:;{}=]+(/[!a-zA-Z0-9\\-_.~@:;{}=]+)*" /* ANY_RESOURCE_ID */), key = "resourceId") {
+ let formatWithCarets = new RegExp(`^${format.source}$`);
+ if (!id.match(formatWithCarets))
+ throw new ValidationError(`Invalid ${key} - ${id}, expected ID of format ${formatWithCarets}.`);
+}
+
+// src/core/rules/resource-id-segments.ts
+function validateResourceIdSegments(resourceIdSegmentValues, resourceIdSegmentFormats) {
+ Object.entries(resourceIdSegmentValues).forEach(([resourceIdKey, resourceIdValue]) => {
+ validateResourceId(resourceIdValue, resourceIdSegmentFormats == null ? void 0 : resourceIdSegmentFormats[resourceIdKey], resourceIdKey);
+ });
+}
+
+// src/core/rules/resource-owner.ts
+function validateResourceOwner(owner, expectedResourceOwner) {
+ if (expectedResourceOwner && owner !== expectedResourceOwner)
+ throw new ValidationError(`Invalid resource owner - ${owner}, expected ${expectedResourceOwner}.`);
+}
+
+// src/core/rules/resource-type.ts
+function validateResourceType(type, expectedResourceType) {
+ if (expectedResourceType && type !== expectedResourceType)
+ throw new ValidationError(`Invalid resource type - ${type}, expected ${expectedResourceType}.`);
+}
+
+// src/core/parser/base.ts
+var NUMBER_OF_BASE_SEGMENTS = 5, SEGMENT_SEPARATOR = ":", BaseParser = class {
+ static getIdentifierSegments(inputStr, numberOfSegmentsRequired) {
+ let allSegments = inputStr.split(SEGMENT_SEPARATOR);
+ if (allSegments.length < numberOfSegmentsRequired)
+ throw new ValidationError(`Input string must have ${numberOfSegmentsRequired} segments.`);
+ if (allSegments.length > numberOfSegmentsRequired) {
+ let segments = allSegments.slice(0, NUMBER_OF_BASE_SEGMENTS - 1), segmentsForResourceId = allSegments.slice(NUMBER_OF_BASE_SEGMENTS - 1, allSegments.length);
+ return [...segments, segmentsForResourceId.join(SEGMENT_SEPARATOR)];
+ }
+ return allSegments;
+ }
+};
+
+// src/core/parser/ari.ts
+var NUMBER_OF_ARI_SEGMENTS = 5, AriParser = class extends BaseParser {
+ static fromString(maybeAri, ariProperties) {
+ let segments = this.getIdentifierSegments(maybeAri, NUMBER_OF_ARI_SEGMENTS), [qualifier, platformQualifier, resourceOwner, cloudId, resourceTypeAndId] = segments, [resourceType, ...resourceIdSegments] = resourceTypeAndId.split("/"), maybeAriDerivedProperties = {
+ qualifier,
+ platformQualifier,
+ cloudId,
+ resourceOwner,
+ resourceType,
+ resourceId: resourceIdSegments.join("/"),
+ resourceIdSegmentValues: ariProperties != null && ariProperties.resourceIdSlug ? this.ariSegmentValuesFromSlug(
+ ariProperties.resourceIdSlug,
+ resourceIdSegments.join("/"),
+ Object.keys(ariProperties.resourceIdSegmentFormats)
+ ) : {}
+ };
+ return this.fromOpts(maybeAriDerivedProperties, ariProperties);
+ }
+ static fromOpts(maybeAriOpts, ariProperties) {
+ let {
+ qualifier = "ari",
+ platformQualifier = "cloud",
+ resourceOwner,
+ cloudId,
+ resourceId,
+ resourceIdSegmentValues,
+ resourceType
+ } = maybeAriOpts;
+ return validateAriQualifier(qualifier), validatePlatformQualifier(platformQualifier), validateCloudId(maybeAriOpts.cloudId || "", ariProperties == null ? void 0 : ariProperties.cloudId), validateResourceOwner(resourceOwner, ariProperties == null ? void 0 : ariProperties.resourceOwner), validateResourceType(resourceType, ariProperties == null ? void 0 : ariProperties.resourceType), validateResourceIdSegments(resourceIdSegmentValues, ariProperties == null ? void 0 : ariProperties.resourceIdSegmentFormats), {
+ qualifier,
+ resourceOwner,
+ resourceType,
+ platformQualifier,
+ cloudId,
+ resourceId,
+ resourceIdSegmentValues
+ };
+ }
+ static ariSegmentValuesFromSlug(slug, incomingSegments, expectedKeys) {
+ let regexpResult = new RegExp("^" + slug.replace(/\{(.*?)\}/g, "(?<$1>.*?)") + "$").exec(incomingSegments);
+ if (!regexpResult)
+ throw new ValidationError(`Segment '${incomingSegments}' don't match expected slug: ${slug}`);
+ return expectedKeys.forEach((expectedKey) => {
+ var _a;
+ if (!((_a = regexpResult.groups) != null && _a[expectedKey]))
+ throw new ValidationError(`No value supplied for '${expectedKey}' based on slug ${slug}`);
+ }), regexpResult.groups || {};
+ }
+};
+
+// src/core/parser/ati.ts
+var NUMBER_OF_ATI_SEGMENTS = 4, AtiParser = class extends BaseParser {
+ static fromString(inputStr, atiOpts) {
+ let segments = this.getIdentifierSegments(inputStr, NUMBER_OF_ATI_SEGMENTS), [qualifier = "ati", platformQualifier = "cloud", resourceOwner, resourceType] = segments;
+ return validateAtiQualifier(qualifier), validatePlatformQualifier(platformQualifier), validateResourceOwner(resourceOwner, atiOpts == null ? void 0 : atiOpts.resourceOwner), validateResourceType(resourceType, atiOpts == null ? void 0 : atiOpts.resourceType), { platformQualifier, resourceOwner, resourceType };
+ }
+ static fromOpts(maybeAtiOpts, atiOpts) {
+ let { qualifier, platformQualifier, resourceOwner, resourceType } = maybeAtiOpts;
+ return validateAtiQualifier(qualifier), validatePlatformQualifier(platformQualifier), validateResourceOwner(resourceOwner, atiOpts == null ? void 0 : atiOpts.resourceOwner), validateResourceType(resourceType, atiOpts == null ? void 0 : atiOpts.resourceType), {
+ platformQualifier,
+ resourceOwner,
+ resourceType
+ };
+ }
+};
+
+// src/ati.ts
+var Ati = class _Ati {
+ constructor(platformQualifier, resourceOwner, resourceType) {
+ this._platformQualifier = platformQualifier, this._resourceOwner = resourceOwner, this._resourceType = resourceType;
+ }
+ get platformQualifier() {
+ return this._platformQualifier;
+ }
+ get resourceOwner() {
+ return this._resourceOwner;
+ }
+ get resourceType() {
+ return this._resourceType;
+ }
+ static create(opts) {
+ return new _Ati(opts.platformQualifier || "cloud", opts.resourceOwner, opts.resourceType);
+ }
+ static parse(maybeAti, atiOpts) {
+ let opts = AtiParser.fromString(maybeAti, atiOpts);
+ return new _Ati(opts.platformQualifier, opts.resourceOwner, opts.resourceType);
+ }
+ toString() {
+ return `ati:${this.platformQualifier}:${this.resourceOwner}:${this.resourceType}`;
+ }
+ toJSON() {
+ return this.toString();
+ }
+ toOpts() {
+ return {
+ platformQualifier: this._platformQualifier,
+ resourceOwner: this._resourceOwner,
+ resourceType: this._resourceType
+ };
+ }
+};
+
+// src/core/ari.ts
+var Ari = class {
+ constructor(opts) {
+ this._ati = Ati.create({
+ platformQualifier: opts.platformQualifier || "cloud",
+ resourceOwner: opts.resourceOwner,
+ resourceType: opts.resourceType
+ }), this._cloudId = opts.cloudId !== "" ? opts.cloudId : void 0, this._resourceId = opts.resourceId;
+ }
+ get platformQualifier() {
+ return this._ati.platformQualifier;
+ }
+ get cloudId() {
+ return this._cloudId;
+ }
+ get resourceOwner() {
+ return this._ati.resourceOwner;
+ }
+ get resourceType() {
+ return this._ati.resourceType;
+ }
+ get resourceId() {
+ return this._resourceId;
+ }
+ get ati() {
+ return this._ati;
+ }
+ equals(other) {
+ return this.toString() === other.toString();
+ }
+ toString() {
+ return `ari:${this.platformQualifier}:${this.resourceOwner}:${this.cloudId || ""}:${this.resourceType}/${this.resourceId}`;
+ }
+ toJSON() {
+ return this.toString();
+ }
+ toOpts() {
+ return {
+ platformQualifier: this.platformQualifier,
+ resourceOwner: this.resourceOwner,
+ cloudId: this.cloudId,
+ resourceType: this.resourceType,
+ resourceId: this.resourceId
+ };
+ }
+};
+
+// src/any-ari.ts
+var AnyAri = class _AnyAri extends Ari {
+ constructor(opts) {
+ super(opts);
+ }
+ static create(ariOpts, ariStaticOpts) {
+ let ariOptsWithDefaults = { ...ariOpts, resourceIdSegmentValues: {} }, validatedOpts = AriParser.fromOpts(ariOptsWithDefaults, ariStaticOpts);
+ return new _AnyAri(validatedOpts);
+ }
+ static parse(maybeAri, ariStaticOpts) {
+ let validatedOpts = AriParser.fromString(maybeAri, ariStaticOpts);
+ return new _AnyAri(validatedOpts);
+ }
+ static check(maybeAri) {
+ try {
+ return _AnyAri.parse(maybeAri.toString()), !0;
+ } catch (err) {
+ return !1;
+ }
+ }
+ asAnyAri() {
+ return this;
+ }
+};
+
+// src/core/registered-ari.ts
+var RegisteredAri = class extends Ari {
+ static check(maybeAri) {
+ try {
+ return this.parse(maybeAri.toString()), !0;
+ } catch (err) {
+ return !1;
+ }
+ }
+ asAnyAri() {
+ return AnyAri.parse(this.toString());
+ }
+};
+
+// src/avp/chart/types.ts
+var AvpChartAriResourceOwner = "avp", AvpChartAriResourceType = "chart";
+
+// src/avp/chart/manifest.ts
+var avpChartAriStaticOpts = {
+ qualifier: "ari",
+ platformQualifier: "cloud",
+ cloudId: new RegExp("^[a-zA-Z0-9_\\-.]{1,255}$"),
+ // eslint-disable-line no-useless-escape
+ resourceOwner: AvpChartAriResourceOwner,
+ resourceType: AvpChartAriResourceType,
+ resourceIdSlug: "activation/{activationId}/{chartId}",
+ resourceIdSegmentFormats: {
+ activationId: /[a-zA-Z0-9\-]+/,
+ // eslint-disable-line no-useless-escape
+ chartId: /[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}/
+ // eslint-disable-line no-useless-escape
+ }
+};
+
+// src/avp/chart/index.ts
+var AvpChartAri = class _AvpChartAri extends RegisteredAri {
+ constructor(opts) {
+ super(opts);
+ this._siteId = opts.cloudId || "", this._activationId = opts.resourceIdSegmentValues.activationId, this._chartId = opts.resourceIdSegmentValues.chartId;
+ }
+ get siteId() {
+ return this._siteId;
+ }
+ get activationId() {
+ return this._activationId;
+ }
+ get chartId() {
+ return this._chartId;
+ }
+ static create(opts) {
+ let derivedOpts = {
+ qualifier: avpChartAriStaticOpts.qualifier,
+ platformQualifier: avpChartAriStaticOpts.platformQualifier,
+ cloudId: opts.siteId,
+ resourceOwner: avpChartAriStaticOpts.resourceOwner,
+ resourceType: avpChartAriStaticOpts.resourceType,
+ resourceId: `activation/${opts.activationId}/${opts.chartId}`,
+ resourceIdSegmentValues: {
+ activationId: opts.activationId,
+ chartId: opts.chartId
+ }
+ }, ariOpts = AriParser.fromOpts(derivedOpts, avpChartAriStaticOpts);
+ return new _AvpChartAri(ariOpts);
+ }
+ static parse(maybeAri) {
+ let opts = AriParser.fromString(maybeAri, avpChartAriStaticOpts);
+ return new _AvpChartAri(opts);
+ }
+ getVariables() {
+ return {
+ siteId: this.siteId,
+ activationId: this.activationId,
+ chartId: this.chartId
+ };
+ }
+};
+// Annotate the CommonJS export names for ESM import in node:
+0 && (module.exports = {
+ AvpChartAri,
+ AvpChartAriResourceOwner,
+ AvpChartAriResourceType
+});