npm package diff
Package: @forge/util
Versions: 1.4.10-next.0 - 1.4.10-next.0-experimental-effab31
File: package/packages/ari/hubspot.hubspot/customer-org/index.js
Index: package/packages/ari/hubspot.hubspot/customer-org/index.js
===================================================================
--- package/packages/ari/hubspot.hubspot/customer-org/index.js
+++ package/packages/ari/hubspot.hubspot/customer-org/index.js
@@ -0,0 +1,343 @@
+"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/hubspot.hubspot/customer-org/index.ts
+var customer_org_exports = {};
+__export(customer_org_exports, {
+ HubspotHubspotCustomerOrgAri: () => HubspotHubspotCustomerOrgAri,
+ HubspotHubspotCustomerOrgAriResourceOwner: () => HubspotHubspotCustomerOrgAriResourceOwner,
+ HubspotHubspotCustomerOrgAriResourceType: () => HubspotHubspotCustomerOrgAriResourceType
+});
+module.exports = __toCommonJS(customer_org_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/hubspot.hubspot/customer-org/types.ts
+var HubspotHubspotCustomerOrgAriResourceOwner = "hubspot.hubspot", HubspotHubspotCustomerOrgAriResourceType = "customer-org";
+
+// src/hubspot.hubspot/customer-org/manifest.ts
+var hubspotHubspotCustomerOrgAriStaticOpts = {
+ qualifier: "ari",
+ platformQualifier: "third-party",
+ cloudId: new RegExp("^$"),
+ // eslint-disable-line no-useless-escape
+ resourceOwner: HubspotHubspotCustomerOrgAriResourceOwner,
+ resourceType: HubspotHubspotCustomerOrgAriResourceType,
+ resourceIdSlug: "portal/{portalId}/customer-org/{customerOrgId}",
+ resourceIdSegmentFormats: {
+ portalId: /[!a-zA-Z0-9\-_.~@:;{}=]+(\/[!a-zA-Z0-9\-_.~@:;{}=]+)*/,
+ // eslint-disable-line no-useless-escape
+ customerOrgId: /[!a-zA-Z0-9\-_.~@:;{}=]+(\/[!a-zA-Z0-9\-_.~@:;{}=]+)*/
+ // eslint-disable-line no-useless-escape
+ }
+};
+
+// src/hubspot.hubspot/customer-org/index.ts
+var HubspotHubspotCustomerOrgAri = class _HubspotHubspotCustomerOrgAri extends RegisteredAri {
+ constructor(opts) {
+ super(opts);
+ this._portalId = opts.resourceIdSegmentValues.portalId, this._customerOrgId = opts.resourceIdSegmentValues.customerOrgId;
+ }
+ get portalId() {
+ return this._portalId;
+ }
+ get customerOrgId() {
+ return this._customerOrgId;
+ }
+ static create(opts) {
+ let derivedOpts = {
+ qualifier: hubspotHubspotCustomerOrgAriStaticOpts.qualifier,
+ platformQualifier: hubspotHubspotCustomerOrgAriStaticOpts.platformQualifier,
+ cloudId: void 0,
+ resourceOwner: hubspotHubspotCustomerOrgAriStaticOpts.resourceOwner,
+ resourceType: hubspotHubspotCustomerOrgAriStaticOpts.resourceType,
+ resourceId: `portal/${opts.portalId}/customer-org/${opts.customerOrgId}`,
+ resourceIdSegmentValues: {
+ portalId: opts.portalId,
+ customerOrgId: opts.customerOrgId
+ }
+ }, ariOpts = AriParser.fromOpts(derivedOpts, hubspotHubspotCustomerOrgAriStaticOpts);
+ return new _HubspotHubspotCustomerOrgAri(ariOpts);
+ }
+ static parse(maybeAri) {
+ let opts = AriParser.fromString(maybeAri, hubspotHubspotCustomerOrgAriStaticOpts);
+ return new _HubspotHubspotCustomerOrgAri(opts);
+ }
+ getVariables() {
+ return {
+ portalId: this.portalId,
+ customerOrgId: this.customerOrgId
+ };
+ }
+};
+// Annotate the CommonJS export names for ESM import in node:
+0 && (module.exports = {
+ HubspotHubspotCustomerOrgAri,
+ HubspotHubspotCustomerOrgAriResourceOwner,
+ HubspotHubspotCustomerOrgAriResourceType
+});