@atlassian/ari
The official TypeScript library for creating, parsing and working with ARIs 🚀
The classes in this repository are auto-generated based upon the ARI Registry. We plan to release a new version of this library at the start of every business week, AEST.
Installation
To install this library, run:
yarn add @atlassian/ari
or
npm i @atlassian/ari
Usage
This library aims to give you the primitives you need to get working with ARIs. To the extent we can, we aim to provide a lightweight API for our consumers.
Importing
You can import a specific ARI class from a few places, depending on your bundle size requirements:
import { ConfluencePageAri } from '@atlassian/ari/confluence';
import { ConfluencePageAri } from '@atlassian/ari/confluence/page';
import { Ari, AnyAri, Ati } from '@atlassian/ari';
Quick start
Most of the methods and classes you can interact with are shown below. For a more detailed reference, keep scrolling until the API reference section.
import { AnyAri, Ati, ResourceOwner, ResourceType } from '@atlassian/ari';
import { ConfluenceSiteAri } from '@atlassian/ari/confluence/site';
const pageAri = ConfluencePageAri.create({
siteId: '123',
pageId: '456',
});
console.log(pageAri.siteId);
console.log(pageAri.pageId);
console.log(pageAri.cloudId);
console.log(pageAri.resourceOwner);
console.log(pageAri.resourceType);
console.log(pageAri.resourceId);
console.log(pageAri.ati);
console.log(ConfluenceSiteAri.check('ari:cloud:jira::site/ee95456c-a203-42dc-b284-7bbb3854457f'));
console.log(ConfluenceSiteAri.check('ari:cloud:confluence::site/ee95456c-a203-42dc-b284-7bbb3854457f'));
const pageAriTheSecond = AnyAri.create({
resourceOwner: ResourceOwner.Confluence,
cloudId: '123',
resourceType: ResourceType.Page,
resourceId: '456',
});
console.log(pageAri.cloudId);
console.log(pageAri.resourceOwner);
console.log(pageAri.resourceType);
console.log(pageAri.resourceId);
console.log(pageAri.ati);
Lastly, here is an example of parsing into a specific ARI type:
import { ConfluencePageAri, JiraIssueAri, TrelloCardAri } from '@atlassian/ari';
const invokeApi = (ari: string): Promise<Ari> => {
if (TrelloCardAri.check(ari)) {
return this.http.client.post(`/trello/api/${ari}`);
}
if (JiraIssueAri.check(ari)) {
return this.http.client.post(`/jira/api/${ari}`);
}
if (ConfluencePageAri.check(ari)) {
return this.http.client.post(`/confluence/api/${ari}`);
}
};
const ari = await invokeApi('ari:cloud:confluence:123:page/456');
console.log(ari.resourceId);
API reference
Working with ARIs
Parsing an ARI
If you are parsing an ARI from the registry, you can use a specific Ari
class to parse from string
to that instance (e.g. ConfluencePageAri
), or the generic Ari
for unregistered ARIs.
import { ConfluencePageAri } from '@atlassian/ari/confluence/page';
const ari = ConfluencePageAri.parse('ari:cloud:confluence:123:page/456');
console.log(ari.siteId);
console.log(ari.pageId);
If you are parsing an ARI which does not exist in the registry (:paddlin:) you can use the core ARI class.
import { AnyAri } from '@atlassian/ari';
const ari = AnyAri.parse('ari:cloud:confluence:123:page/456');
console.log(ari.cloudId);
console.log(ari.resourceId);
Note: if the invocation of .parse()
fails, a ValidationError
will be thrown.
import { AnyAri } from '@atlassian/ari';
try {
const ari = AnyAri.parse('ari:cloud:confluence:123:unregistered-ari/456');
} catch (err) {
if (err.constructor.name === 'ValidationError') {
}
}
Creating an ARI
If you are creating an ARI from the registry, you can use a specific Ari
class to create from a set of options for that instance in conformance with its definition in the ARI registry (e.g. ConfluencePageAri
), or the generic Ari
for unregistered ARIs.
import { ConfluencePageAri } from '@atlassian/ari/confluence/page';
const ari = ConfluencePageAri.create({
siteId: '123',
pageId: '456',
});
console.log(ari.siteId);
console.log(ari.pageId);
If you are creating an ARI which does not exist in the registry (double :paddlin:) you can use the core ARI class.
import { AnyAri } from '@atlassian/ari';
const ari = AnyAri.create({
resourceOwner: 'confluence',
cloudId: '123',
resourceType: 'page',
resourceId: '456',
});
console.log(ari.cloudId);
console.log(ari.resourceId);
Note: if the invocation of .create()
or parse()
fails, a ValidationError
will be thrown.
import { AnyAri } from '@atlassian/ari';
try {
const ari = AnyAri.parse('ari:cloud:confluence:123:unregistered-ari/456');
} catch (err) {
if (err.constructor.name === 'ValidationError') {
}
}
Checking ARIs
You can use the check()
function to determine if an ARI string or class fits the requirements of a certain ARI.
import { AnyAri, ConfluenceSiteAri, JiraSiteAri } from '@atlassian/ari';
const result1 = AnyAri.check(ConfluenceSiteAri.create({ siteId: 'ee95456c-a203-42dc-b284-7bbb3854457f' }));
const result2 = JiraSiteAri.check('ari:cloud:confluence::site/ee95456c-a203-42dc-b284-7bbb3854457f');
console.log(result1);
console.log(result2);
Working with ATIs
Parsing an ATI
For ATIs, the use of more specific instance is not required. The core Ati
class should be used:
import { Ati, ResourceOwner, ResourceType } from '@atlassian/ari';
const ati = Ati.parse('ati:cloud:confluence:page');
console.log(ati.resourceOwner);
console.log(ati.resourceType);
Creating an ATI
For ATIs, the use of more specific instance is not required. The core Ati
class should be used:
import { Ati, ResourceOwner, ResourceType } from '@atlassian/ari';
const ati = Ati.create({
resourceOwner: ResourceOwner.Confluence,
resourceType: ResourceType.Page,
});
console.log(ati.toString());
Working with ARMs
Parsing an ARM
ARMs are exposed through the top-level Arm
class. To parse an ARM string do the following:
import { Arm } from '@atlassian/ari';
const arm = Arm.parse('arm:cloud:jira.*::board/.+');
console.log(arm.resourceOwnerMatcher);
console.log(arm.resourceTypeMatcher);
Creating an ARM
You can create an ARM using the same Arm
class mentioned above!
import { Arm } from '@atlassian/ari';
const arm = Arm.create({
resourceOwnerMatcher: 'jira.*',
cloudIdMatcher: '',
resourceTypeMatcher: 'board',
resourceIdMatcher: '.+',
});
console.log(arm.toString());
Matching an ARI against an ARM
You can match ARIs against ARMs using the .match
method on ARM instances:
import { Arm } from '@atlassian/ari';
import { ConfluencePageAri } from '@atlassian/ari/confluence/page';
const ari = ConfluencePageAri.create({
siteId: '123',
pageId: '456',
});
const arm = Arm.create({
resourceOwnerMatcher: 'confluence',
cloudIdMatcher: '[0-9]+',
resourceTypeMatcher: 'page',
resourceIdMatcher: '.+',
});
console.log(arm.match(ari));
FAQ
I have a feature request - where should I raise it?
Please create a ticket on this Trello board. We will try to get back to you ASAP!
I cannot see an ARI which should exist in this repository. What do I do?
Try to figure out who the resource owner of the ARI is, and kindly ask them to add their ARI to the ARI Registry YAML 😄
We auto-generate classes based on what exists in the registry. Teams should be reflecting their ARI back into it, using the process defined here.
If your ARI has recently been added to the registry, you will have to wait until the start of the next business week (AEST) for the changes to be reflected in this library.
I need a change to go through urgently. Who do I speak to?
Come and chat to us in the #ari-working-group channel!
Contributing
If you're keen on helping us build out this library, reach out to us in #ari-working-group 😄
As a Working Group, we meet every fortnight. Library developers and maintainers will be present - we'd love to meet you and collaborate with you on this!