@aptly-as/app-sdk
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -1,17 +0,15 @@ | ||
import { RequestInit } from 'node-fetch'; | ||
import type { RequestInit } from 'node-fetch'; | ||
import { AptlyApi } from './aptly/AptlyApi.js'; | ||
import { AptlyOrganization } from './aptly/AptlyOrganization.js'; | ||
import { AptlyProducts } from './aptly/AptlyProducts.js'; | ||
export { AptlyApiOAuth2Response } from './aptly/AptlyApi'; | ||
export type { AptlyApiOAuth2Response } from './aptly/AptlyApi.js'; | ||
export declare class Aptly { | ||
readonly api: AptlyApi; | ||
readonly _products: AptlyProducts; | ||
private _organization; | ||
private organizationID; | ||
constructor(url: string, client_id: string, client_secret: string); | ||
init(refresh_token: string, ID: string): void; | ||
init(refresh_token: string, organizationID: string): void; | ||
fetch<T>(path: string, init?: RequestInit): Promise<T>; | ||
set accessToken(token: string); | ||
get organization(): AptlyOrganization; | ||
get products(): AptlyProducts; | ||
organization(id?: string): AptlyOrganization; | ||
products(): AptlyProducts; | ||
} | ||
//# sourceMappingURL=Aptly.d.ts.map |
@@ -6,8 +6,8 @@ import { AptlyApi } from './aptly/AptlyApi.js'; | ||
constructor(url, client_id, client_secret) { | ||
this.organizationID = ''; | ||
this.api = new AptlyApi(url, client_id, client_secret); | ||
this._products = new AptlyProducts(this.api, 'api/v1'); | ||
} | ||
init(refresh_token, ID) { | ||
init(refresh_token, organizationID) { | ||
this.api.init(refresh_token); | ||
this._organization = new AptlyOrganization(this.api, ID, 'api/v1'); | ||
this.organizationID = organizationID; | ||
} | ||
@@ -20,8 +20,10 @@ fetch(path, init) { | ||
} | ||
get organization() { | ||
return this._organization; | ||
organization(id = this.organizationID) { | ||
if (!id) | ||
throw new Error('Organization ID is required'); | ||
return new AptlyOrganization(this.api, 'api/v1', id); | ||
} | ||
get products() { | ||
return this._products; | ||
products() { | ||
return new AptlyProducts(this.api, 'api/v1'); | ||
} | ||
} |
@@ -28,2 +28,1 @@ import { AptlyAppJWT } from '@aptly-as/types'; | ||
} | ||
//# sourceMappingURL=AptlyApi.d.ts.map |
@@ -0,3 +1,4 @@ | ||
import { AptlyApiError, AptlyErrorCode } from '@aptly-as/types'; | ||
import jwt from 'jsonwebtoken'; | ||
import fetch, { Headers } from 'node-fetch'; | ||
import jwt from 'jsonwebtoken'; | ||
import { sleep } from '../utils.js'; | ||
@@ -32,2 +33,3 @@ export class AptlyApi { | ||
async fetch(path, init) { | ||
let response; | ||
try { | ||
@@ -41,13 +43,22 @@ while (this.busy) { | ||
} | ||
const response = await fetch(`${this.url}/${path}`, { | ||
response = await fetch(`${this.url}/${path}`, { | ||
headers: this.getJSONHeaders(init), | ||
...init, | ||
}); | ||
if (response.status !== 200) { | ||
throw await response.json(); | ||
if (response.status > 299) { | ||
throw new AptlyApiError(await response.json()); | ||
} | ||
return (await response.json()); | ||
} | ||
catch (e) { | ||
throw e; | ||
catch (error) { | ||
throw new AptlyApiError({ | ||
status: String(response.status), | ||
detail: 'Failed to parse json', | ||
code: AptlyErrorCode.Default, | ||
link: '', | ||
title: 'Failed to parse json', | ||
id: 'none', | ||
error, | ||
response: response | ||
}); | ||
} | ||
@@ -54,0 +65,0 @@ finally { |
import { AptlyApi } from './AptlyApi.js'; | ||
import { AptlyProducts } from './AptlyProducts.js'; | ||
import { AptlyUnits } from './AptlyUnits.js'; | ||
import { AptlyDocuments } from './AptlyDocuments.js'; | ||
import { AptlyProjects } from './AptlyProjects.js'; | ||
export declare class AptlyOrganization { | ||
private api; | ||
readonly id: string; | ||
readonly path: string; | ||
readonly products: AptlyProducts; | ||
constructor(api: AptlyApi, ID: string, path: string); | ||
constructor(api: AptlyApi, path: string, id: string); | ||
products(): AptlyProducts; | ||
documents(): AptlyDocuments; | ||
projects(): AptlyProjects; | ||
units(): AptlyUnits; | ||
project(projectID: string): AptlyProjects; | ||
unit(unitID: string): AptlyUnits; | ||
get(): Promise<unknown>; | ||
} | ||
//# sourceMappingURL=AptlyOrganization.d.ts.map |
import { AptlyProducts } from './AptlyProducts.js'; | ||
import { AptlyUnits } from './AptlyUnits.js'; | ||
import { AptlyDocuments } from './AptlyDocuments.js'; | ||
import { AptlyProjects } from './AptlyProjects.js'; | ||
export class AptlyOrganization { | ||
constructor(api, ID, path) { | ||
constructor(api, path, id) { | ||
this.api = api; | ||
this.path = `${path}/organizations/${ID}`; | ||
this.products = new AptlyProducts(api, this.path); | ||
this.id = id; | ||
this.path = `${path}/organizations`; | ||
} | ||
products() { | ||
return new AptlyProducts(this.api, `${this.path}/${this.id}`); | ||
} | ||
documents() { | ||
return new AptlyDocuments(this.api, `${this.path}/${this.id}`); | ||
} | ||
projects() { | ||
return new AptlyProjects(this.api, `${this.path}/${this.id}`); | ||
} | ||
units() { | ||
return new AptlyUnits(this.api, `${this.path}/${this.id}`); | ||
} | ||
project(projectID) { | ||
return new AptlyProjects(this.api, `${this.path}/${this.id}`, projectID); | ||
} | ||
unit(unitID) { | ||
return new AptlyUnits(this.api, `${this.path}/${this.id}`, unitID); | ||
} | ||
get() { | ||
@@ -9,0 +30,0 @@ return this.api.get(this.path); |
@@ -12,2 +12,1 @@ import { AptlyApiQueries, AptlyProduct, AptlySearchPaginateResponse } from '@aptly-as/types'; | ||
} | ||
//# sourceMappingURL=AptlyProducts.d.ts.map |
@@ -17,2 +17,1 @@ import { AptlyAppAuthorizeCode } from '@aptly-as/types'; | ||
} | ||
//# sourceMappingURL=AptlyCrypto.d.ts.map |
@@ -12,2 +12,6 @@ /// <reference types="node" /> | ||
} | ||
export interface IAptlyOAuth2Props { | ||
authorizeCallbackPath?: string; | ||
installCallbackPath?: string; | ||
} | ||
export declare class AptlyOAuth2 { | ||
@@ -19,2 +23,3 @@ private APTLY_API_URL; | ||
private scope; | ||
private props; | ||
readonly header_organization = "x-aptly-organization"; | ||
@@ -24,4 +29,6 @@ readonly header_body_hmac = "x-aptly-body-sha256"; | ||
readonly crypto: AptlyCrypto; | ||
constructor(APTLY_API_URL: string, APP_API_URL: string, client_id: string, client_secret: string, scope: AptlyScope[]); | ||
constructor(APTLY_API_URL: string, APP_API_URL: string, client_id: string, client_secret: string, scope: AptlyScope[], props?: IAptlyOAuth2Props); | ||
get url(): string; | ||
get authorizeCallbackPath(): string; | ||
get installCallbackPath(): string; | ||
getInstallCallbackRedirect(callback_uri: string): string; | ||
@@ -40,2 +47,1 @@ verifyInstallCallback(url: string, query: URLSearchParams | string | Record<string, string | ReadonlyArray<string>> | Iterable<[string, string]> | ReadonlyArray<[string, string]> | NodeJS.Dict<string | string[]>): IAptlyAppRedirectSuccessProps; | ||
} | ||
//# sourceMappingURL=AptlyOAuth2.d.ts.map |
@@ -6,3 +6,3 @@ import jwt from 'jsonwebtoken'; | ||
export class AptlyOAuth2 { | ||
constructor(APTLY_API_URL, APP_API_URL, client_id, client_secret, scope) { | ||
constructor(APTLY_API_URL, APP_API_URL, client_id, client_secret, scope, props = {}) { | ||
this.APTLY_API_URL = APTLY_API_URL; | ||
@@ -13,2 +13,3 @@ this.APP_API_URL = APP_API_URL; | ||
this.scope = scope; | ||
this.props = props; | ||
this.header_organization = 'x-aptly-organization'; | ||
@@ -34,4 +35,10 @@ this.header_body_hmac = 'x-aptly-body-sha256'; | ||
} | ||
get authorizeCallbackPath() { | ||
return this.props.authorizeCallbackPath || '/aptly/authorize/callback'; | ||
} | ||
get installCallbackPath() { | ||
return this.props.installCallbackPath || '/aptly/install/callback'; | ||
} | ||
getInstallCallbackRedirect(callback_uri) { | ||
const redirect_uri = `${this.APP_API_URL}/install/callback`; | ||
const redirect_uri = `${this.APP_API_URL}${this.installCallbackPath}`; | ||
const params = this.getRedirectParams(redirect_uri); | ||
@@ -80,3 +87,3 @@ const url = `${callback_uri}?${params.toString()}`; | ||
getAuthorizeRedirect(organization, path) { | ||
const redirect_uri = `${this.APP_API_URL}/authorize/callback`; | ||
const redirect_uri = `${this.APP_API_URL}${this.authorizeCallbackPath}`; | ||
const search = new URLSearchParams({ redirect_uri, state: path }); | ||
@@ -83,0 +90,0 @@ return `${this.url}/api/v1/organizations/${organization}/apps/${this.client_id}/authorize?${search.toString()}`; |
export * from './Aptly.js'; | ||
export * from './AptlyOAuth2.js'; | ||
//# sourceMappingURL=index.d.ts.map |
export declare const sleep: (ms: number) => Promise<unknown>; | ||
//# sourceMappingURL=utils.d.ts.map |
{ | ||
"name": "@aptly-as/app-sdk", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Aptly app SDK library for app communication and frontend development", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25807
635
4
25