New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@forge/storage

Package Overview
Dependencies
Maintainers
0
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@forge/storage - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0-next.0

42

out/__test__/global-storage.test.js

@@ -7,4 +7,3 @@ "use strict";

const mocks_1 = require("@atlassian/metrics-interface/dist/mocks");
const contextAri = 'app-ari';
const getStorage = (apiClientMock, metrics) => new global_storage_1.GlobalStorage(() => contextAri, apiClientMock, () => metrics);
const getStorage = (apiClientMock, metrics) => new global_storage_1.GlobalStorage(apiClientMock, () => metrics);
const getApiClientMock = (response, statusCode = 200) => {

@@ -76,7 +75,2 @@ return jest.fn().mockReturnValue({

}
beforeEach(() => {
global.api = {
__getAppAri: jest.fn().mockReturnValue(contextAri)
};
});
describe('get', () => {

@@ -95,3 +89,2 @@ it('should call the storage API, passing the provided key and returning the stored value', async () => {

verifyApiClientCalledWith(apiClientMock, {
contextAri,
key: 'testKey',

@@ -117,3 +110,2 @@ encrypted: false

verifyApiClientCalledWith(apiClientMock, {
contextAri,
key: 'testKey',

@@ -139,3 +131,2 @@ encrypted: false

verifyApiClientCalledWith(apiClientMock, {
contextAri,
key: 'testKey',

@@ -161,3 +152,2 @@ encrypted: false

verifyApiClientCalledWith(apiClientMock, {
contextAri,
key: 'testKey',

@@ -220,3 +210,2 @@ encrypted: false

verifyApiClientCalledWith(apiClientMock, {
contextAri,
key: 'testKey',

@@ -247,3 +236,2 @@ encrypted: true

input: {
contextAri,
key: 'testKey',

@@ -304,3 +292,2 @@ value: 'testValue',

input: {
contextAri,
key: 'testKey',

@@ -332,3 +319,2 @@ value: 'testValue',

input: {
contextAri,
key: 'testKey',

@@ -360,3 +346,2 @@ value: 'testValue',

input: {
contextAri,
key: 'testKey',

@@ -418,3 +403,2 @@ encrypted: false

input: {
contextAri,
key: 'testKey',

@@ -442,3 +426,2 @@ encrypted: true

verifyApiClientCalledWith(apiClientMock, {
contextAri,
entityName: 'testEntityName',

@@ -464,3 +447,2 @@ key: 'testEntityKey'

verifyApiClientCalledWith(apiClientMock, {
contextAri,
entityName: 'testEntityName',

@@ -486,3 +468,2 @@ key: 'testEntityKey'

verifyApiClientCalledWith(apiClientMock, {
contextAri,
entityName: 'testEntityName',

@@ -508,3 +489,2 @@ key: 'testEntityKey'

verifyApiClientCalledWith(apiClientMock, {
contextAri,
entityName: 'testEntityName',

@@ -570,3 +550,2 @@ key: 'testEntityKey'

input: {
contextAri,
entityName: 'testEntityName',

@@ -627,3 +606,2 @@ key: 'testEntityKey',

input: {
contextAri,
entityName: 'testEntityName',

@@ -655,3 +633,2 @@ key: 'testEntityKey',

input: {
contextAri,
entityName: 'testEntityName',

@@ -722,7 +699,6 @@ key: 'testEntityKey'

verifyApiClientCalledWith(apiClientMock, {
contextAri,
where,
cursor,
limit
}, gql_queries_1.UntypedQueries.listQuery(contextAri, {}).query);
}, gql_queries_1.UntypedQueries.listQuery({}).query);
expect(response).toEqual(expect.objectContaining({

@@ -764,7 +740,6 @@ results: [

verifyApiClientCalledWith(apiClientMock, {
contextAri,
where,
cursor,
limit
}, gql_queries_1.UntypedQueries.listQueryForCleanup(contextAri, {}).query);
}, gql_queries_1.UntypedQueries.listQueryForCleanup({}).query);
expect(response).toEqual(expect.objectContaining({

@@ -794,7 +769,6 @@ results: [

verifyApiClientCalledWith(apiClientMock, {
contextAri,
where: null,
cursor: null,
limit: null
}, gql_queries_1.UntypedQueries.listQuery(contextAri, {}).query);
}, gql_queries_1.UntypedQueries.listQuery({}).query);
passMetrics

@@ -871,5 +845,3 @@ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true)

});
verifyApiClientCalledWith(apiClientMock, {
contextAri
}, gql_queries_1.CustomEntityQueries.listQuery(contextAri, {}).query);
verifyApiClientCalledWith(apiClientMock, {}, gql_queries_1.CustomEntityQueries.listQuery({}).query);
passMetrics

@@ -895,5 +867,3 @@ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, true)

});
verifyApiClientCalledWith(apiClientMock, {
contextAri
}, gql_queries_1.CustomEntityQueries.listQuery(contextAri, {}).query);
verifyApiClientCalledWith(apiClientMock, {}, gql_queries_1.CustomEntityQueries.listQuery({}).query);
passMetrics

@@ -900,0 +870,0 @@ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, true)

4

out/global-storage.d.ts

@@ -15,8 +15,6 @@ import { FetchMethod } from './index';

export declare class GlobalStorage implements SharedStorageAdapter {
private getAppContextAri;
private apiClient;
private readonly getMetrics;
private readonly endpoint;
constructor(getAppContextAri: (() => string) | string, apiClient: FetchMethod, getMetrics: () => Metrics | undefined);
private doGetAppContextAri;
constructor(apiClient: FetchMethod, getMetrics: () => Metrics | undefined);
get(key: string): Promise<any>;

@@ -23,0 +21,0 @@ getSecret(key: string): Promise<any>;

@@ -28,14 +28,9 @@ "use strict";

class GlobalStorage {
getAppContextAri;
apiClient;
getMetrics;
endpoint = '/forge/entities/graphql';
constructor(getAppContextAri, apiClient, getMetrics) {
this.getAppContextAri = getAppContextAri;
constructor(apiClient, getMetrics) {
this.apiClient = apiClient;
this.getMetrics = getMetrics;
}
doGetAppContextAri() {
return typeof this.getAppContextAri === 'function' ? this.getAppContextAri() : this.getAppContextAri;
}
async get(key) {

@@ -49,4 +44,4 @@ return this.getInternal(key, false);

const requestBody = process.env.IS_CLEANUP_FUNCTION === 'true'
? gql_queries_1.UntypedQueries.listQueryForCleanup(this.doGetAppContextAri(), options)
: gql_queries_1.UntypedQueries.listQuery(this.doGetAppContextAri(), options);
? gql_queries_1.UntypedQueries.listQueryForCleanup(options)
: gql_queries_1.UntypedQueries.listQuery(options);
const response = await this.wrapInMetric('untyped', 'query', false, async () => await this.query(requestBody));

@@ -64,3 +59,3 @@ const edges = process.env.IS_CLEANUP_FUNCTION === 'true'

async listCustomEntities(options) {
const requestBody = gql_queries_1.CustomEntityQueries.listQuery(this.doGetAppContextAri(), options);
const requestBody = gql_queries_1.CustomEntityQueries.listQuery(options);
const response = await this.wrapInMetric('typed', 'query', false, async () => await this.query(requestBody));

@@ -75,15 +70,15 @@ const edges = response.appStoredCustomEntities.edges;

async set(key, value) {
const requestBody = gql_queries_1.UntypedQueries.set(this.doGetAppContextAri(), key, value, false);
const requestBody = gql_queries_1.UntypedQueries.set(key, value, false);
await this.wrapInMetric('untyped', 'set', false, async () => await this.mutation(requestBody, 'appStorage', 'setAppStoredEntity'));
}
async setSecret(key, value) {
const requestBody = gql_queries_1.UntypedQueries.set(this.doGetAppContextAri(), key, value, true);
const requestBody = gql_queries_1.UntypedQueries.set(key, value, true);
await this.wrapInMetric('untyped', 'set', true, async () => await this.mutation(requestBody, 'appStorage', 'setAppStoredEntity'));
}
async delete(key) {
const requestBody = gql_queries_1.UntypedQueries.delete(this.doGetAppContextAri(), key, false);
const requestBody = gql_queries_1.UntypedQueries.delete(key, false);
await this.wrapInMetric('untyped', 'delete', false, async () => this.mutation(requestBody, 'appStorage', 'deleteAppStoredEntity'));
}
async deleteSecret(key) {
const requestBody = gql_queries_1.UntypedQueries.delete(this.doGetAppContextAri(), key, true);
const requestBody = gql_queries_1.UntypedQueries.delete(key, true);
await this.wrapInMetric('untyped', 'delete', true, async () => this.mutation(requestBody, 'appStorage', 'deleteAppStoredEntity'));

@@ -95,11 +90,11 @@ }

async setEntity(entityName, entityKey, value) {
const requestBody = gql_queries_1.CustomEntityQueries.set(this.doGetAppContextAri(), entityName, entityKey, value);
const requestBody = gql_queries_1.CustomEntityQueries.set(entityName, entityKey, value);
await this.wrapInMetric('typed', 'set', false, async () => this.mutation(requestBody, 'appStorageCustomEntity', 'setAppStoredCustomEntity'));
}
async deleteEntity(entityName, entityKey) {
const requestBody = gql_queries_1.CustomEntityQueries.delete(this.doGetAppContextAri(), entityName, entityKey);
const requestBody = gql_queries_1.CustomEntityQueries.delete(entityName, entityKey);
await this.wrapInMetric('typed', 'delete', false, async () => await this.mutation(requestBody, 'appStorageCustomEntity', 'deleteAppStoredCustomEntity'));
}
async getInternal(key, encrypted) {
const requestBody = gql_queries_1.UntypedQueries.get(this.doGetAppContextAri(), key, encrypted);
const requestBody = gql_queries_1.UntypedQueries.get(key, encrypted);
const { appStoredEntity: { value } } = await this.wrapInMetric('untyped', 'get', encrypted, async () => await this.query(requestBody));

@@ -109,3 +104,3 @@ return value ?? undefined;

async getEntityInternal(entityName, entityKey) {
const requestBody = gql_queries_1.CustomEntityQueries.get(this.doGetAppContextAri(), entityName, entityKey);
const requestBody = gql_queries_1.CustomEntityQueries.get(entityName, entityKey);
const { appStoredCustomEntity: { value } } = await this.wrapInMetric('typed', 'get', false, async () => await this.query(requestBody));

@@ -112,0 +107,0 @@ return value ?? undefined;

import { CustomEntityListOptions, ListOptions } from './query-interfaces';
export declare class UntypedQueries {
static get: (contextAri: string, key: string, encrypted: boolean) => {
static get: (key: string, encrypted: boolean) => {
query: string;
variables: {
contextAri: string;
key: string;

@@ -11,7 +10,6 @@ encrypted: boolean;

};
static set: (contextAri: string, key: string, value: any, encrypted: boolean) => {
static set: (key: string, value: any, encrypted: boolean) => {
query: string;
variables: {
input: {
contextAri: string;
key: string;

@@ -23,7 +21,6 @@ value: any;

};
static delete: (contextAri: string, key: string, encrypted: boolean) => {
static delete: (key: string, encrypted: boolean) => {
query: string;
variables: {
input: {
contextAri: string;
key: string;

@@ -34,6 +31,5 @@ encrypted: boolean;

};
static listQuery: (contextAri: string, options: ListOptions) => {
static listQuery: (options: ListOptions) => {
query: string;
variables: {
contextAri: string;
where: import("./query-interfaces").WhereClause[] | null;

@@ -44,6 +40,5 @@ cursor: string | null;

};
static listQueryForCleanup: (contextAri: string, options: ListOptions) => {
static listQueryForCleanup: (options: ListOptions) => {
query: string;
variables: {
contextAri: string;
where: import("./query-interfaces").WhereClause[] | null;

@@ -56,6 +51,5 @@ cursor: string | null;

export declare class CustomEntityQueries {
static get: (contextAri: string, entityName: string, key: string) => {
static get: (entityName: string, key: string) => {
query: string;
variables: {
contextAri: string;
entityName: string;

@@ -65,7 +59,6 @@ key: string;

};
static set: (contextAri: string, entityName: string, key: string, value: any) => {
static set: (entityName: string, key: string, value: any) => {
query: string;
variables: {
input: {
contextAri: string;
entityName: string;

@@ -77,7 +70,6 @@ key: string;

};
static delete: (contextAri: string, entityName: string, key: string) => {
static delete: (entityName: string, key: string) => {
query: string;
variables: {
input: {
contextAri: string;
entityName: string;

@@ -88,3 +80,3 @@ key: string;

};
static listQuery: (contextAri: string, options: CustomEntityListOptions) => {
static listQuery: (options: CustomEntityListOptions) => {
query: string;

@@ -99,3 +91,2 @@ variables: {

} | undefined;
contextAri: string;
entityName: string | undefined;

@@ -102,0 +93,0 @@ indexName: string | undefined;

@@ -5,6 +5,6 @@ "use strict";

class UntypedQueries {
static get = (contextAri, key, encrypted) => ({
static get = (key, encrypted) => ({
query: `
query forge_app_getApplicationStorageEntity($contextAri: ID!, $key: ID!, $encrypted: Boolean!) {
appStoredEntity(contextAri: $contextAri, key: $key, encrypted: $encrypted) {
query forge_app_getApplicationStorageEntity($key: ID!, $encrypted: Boolean!) {
appStoredEntity(key: $key, encrypted: $encrypted) {
key

@@ -16,3 +16,2 @@ value

variables: {
contextAri,
key,

@@ -22,3 +21,3 @@ encrypted

});
static set = (contextAri, key, value, encrypted) => ({
static set = (key, value, encrypted) => ({
query: `

@@ -43,3 +42,2 @@ mutation forge_app_setApplicationStorageEntity($input: SetAppStoredEntityMutationInput!) {

input: {
contextAri,
key,

@@ -51,3 +49,3 @@ value,

});
static delete = (contextAri, key, encrypted) => ({
static delete = (key, encrypted) => ({
query: `

@@ -72,3 +70,2 @@ mutation forge_app_deleteApplicationStorageEntity($input: DeleteAppStoredEntityMutationInput!) {

input: {
contextAri,
key,

@@ -79,6 +76,6 @@ encrypted

});
static listQuery = (contextAri, options) => ({
static listQuery = (options) => ({
query: `
query forge_app_getApplicationStorageEntities($contextAri: ID!, $where: [AppStoredEntityFilter!], $cursor: String, $limit: Int) {
appStoredEntities(contextAri: $contextAri, where: $where, after: $cursor, first: $limit) {
query forge_app_getApplicationStorageEntities($where: [AppStoredEntityFilter!], $cursor: String, $limit: Int) {
appStoredEntities(where: $where, after: $cursor, first: $limit) {
edges {

@@ -96,3 +93,2 @@ node {

variables: {
contextAri,
where: options.where ?? null,

@@ -103,6 +99,6 @@ cursor: options.cursor ?? null,

});
static listQueryForCleanup = (contextAri, options) => ({
static listQueryForCleanup = (options) => ({
query: `
query forge_app_getApplicationStorageEntitiesForCleanup($contextAri: ID!, $where: [AppStoredEntityFilter!], $cursor: String, $limit: Int) {
appStoredEntitiesForCleanup(contextAri: $contextAri, where: $where, after: $cursor, first: $limit) {
query forge_app_getApplicationStorageEntitiesForCleanup($where: [AppStoredEntityFilter!], $cursor: String, $limit: Int) {
appStoredEntitiesForCleanup(where: $where, after: $cursor, first: $limit) {
edges {

@@ -120,3 +116,2 @@ node {

variables: {
contextAri,
where: options.where ?? null,

@@ -130,6 +125,6 @@ cursor: options.cursor ?? null,

class CustomEntityQueries {
static get = (contextAri, entityName, key) => ({
static get = (entityName, key) => ({
query: `
query forge_app_getApplicationStorageCustomEntity ($contextAri: ID!, $key: ID!, $entityName: String!) {
appStoredCustomEntity(contextAri: $contextAri, key: $key, entityName: $entityName) {
query forge_app_getApplicationStorageCustomEntity ($key: ID!, $entityName: String!) {
appStoredCustomEntity(key: $key, entityName: $entityName) {
value

@@ -142,3 +137,2 @@ entityName

variables: {
contextAri,
entityName,

@@ -148,3 +142,3 @@ key

});
static set = (contextAri, entityName, key, value) => ({
static set = (entityName, key, value) => ({
query: `

@@ -169,3 +163,2 @@ mutation forge_app_setApplicationStorageCustomEntity($input: SetAppStoredCustomEntityMutationInput!) {

input: {
contextAri,
entityName,

@@ -177,3 +170,3 @@ key,

});
static delete = (contextAri, entityName, key) => ({
static delete = (entityName, key) => ({
query: `

@@ -198,3 +191,2 @@ mutation forge_app_deleteApplicationStorageCustomEntity($input: DeleteAppStoredCustomEntityMutationInput!) {

input: {
contextAri,
entityName,

@@ -205,7 +197,7 @@ key

});
static listQuery = (contextAri, options) => {
static listQuery = (options) => {
return {
query: `
query AppStorageCustomEntityQueries ($contextAri: ID!, $entityName: String!, $indexName: String!, $range: AppStoredCustomEntityRange, $filters: AppStoredCustomEntityFilters, $sort:SortOrder, $limit: Int, $cursor: String, $partition: [AppStoredCustomEntityFieldValue!]) {
appStoredCustomEntities(contextAri: $contextAri, entityName: $entityName, indexName: $indexName, range: $range, filters: $filters, sort:$sort, limit: $limit, cursor: $cursor, partition: $partition) {
query AppStorageCustomEntityQueries ($entityName: String!, $indexName: String!, $range: AppStoredCustomEntityRange, $filters: AppStoredCustomEntityFilters, $sort:SortOrder, $limit: Int, $cursor: String, $partition: [AppStoredCustomEntityFieldValue!]) {
appStoredCustomEntities(entityName: $entityName, indexName: $indexName, range: $range, filters: $filters, sort:$sort, limit: $limit, cursor: $cursor, partition: $partition) {
edges {

@@ -228,3 +220,2 @@ node {

variables: {
contextAri,
entityName: options.entityName,

@@ -231,0 +222,0 @@ indexName: options.indexName,

{
"name": "@forge/storage",
"version": "1.6.0",
"version": "1.7.0-next.0",
"description": "Forge Storage methods",

@@ -21,5 +21,5 @@ "author": "Atlassian",

"node-fetch": "2.7.0",
"@forge/util": "1.4.4",
"@forge/util": "1.4.6",
"@atlassian/metrics-interface": "4.0.0"
}
}

@@ -28,3 +28,2 @@ Common library for both Forge environment and Harmonised Connect app environment.

'User-Agent': `H11n/${version} ${appAri}`,
'X-Forge-Context': appContextAri,

@@ -31,0 +30,0 @@ Authorization: `Bearer ${token}`

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc