Skip to content

Commit

Permalink
fix: corepack compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Nov 21, 2024
1 parent 797bf7f commit 40c19fe
Show file tree
Hide file tree
Showing 26 changed files with 70 additions and 987 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ dist

# yarn v2
.yarn/*
!.yarn/releases
!.yarn/plugins
!.yarn/versions
.pnp.*
Expand Down
934 changes: 0 additions & 934 deletions .yarn/releases/yarn-4.5.1.cjs

This file was deleted.

2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ignorePath: true

compressionLevel: mixed

enableGlobalCache: false
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@
"volta": {
"node": "22.9.0"
}
}
}
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,4 @@ export const { config } = await libConfig({
config.set(
'laserfiche.baseFolder',
join('/', config.get('laserfiche.baseFolder') ?? '') as `/${string}`,
);
);
20 changes: 10 additions & 10 deletions src/cws/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const {

let authToken: string | null = token;
let isRefreshing = false;
let refreshQueue : any[] = [];
let refreshQueue: any[] = [];

const client: Got = got.extend({
prefixUrl: apiRoot,
Expand Down Expand Up @@ -79,16 +79,17 @@ export const cws = client.extend({
hooks: {
beforeRequest: [
(options: any) => {
options.headers.Authorization = authToken
}
options.headers.Authorization = authToken;
},
],
beforeError: [
async (error: any) => {
const { response } = error;
if (response && response.statusCode === 401) {
try {
authToken = await refreshAuthToken();
error.request.options.headers['Authorization'] = `Bearer ${authToken}`;
error.request.options.headers['Authorization'] =
`Bearer ${authToken}`;
// Retry the original request with the new token
return client(error.request.options);
} catch (tokenRefreshError) {
Expand All @@ -97,10 +98,9 @@ export const cws = client.extend({
}

return error;
}
]
}

},
],
},
});

const refreshAuthToken = async (): Promise<string> => {
Expand All @@ -112,7 +112,7 @@ const refreshAuthToken = async (): Promise<string> => {
isRefreshing = false;

// Resolve all the pending requests in the queue with the new token
refreshQueue.forEach(callback => callback(authToken));
refreshQueue.forEach((callback) => callback(authToken));
refreshQueue = [];
} catch (error) {
isRefreshing = false;
Expand All @@ -121,7 +121,7 @@ const refreshAuthToken = async (): Promise<string> => {
}

// Return a promise that resolves with the new token
return new Promise(resolve => refreshQueue.push(resolve));
return new Promise((resolve) => refreshQueue.push(resolve));
};

export default cws;
2 changes: 1 addition & 1 deletion src/cws/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ export async function retrieveDocument(document: EntryIdLike<DocumentEntry>) {
searchParams: { LaserficheEntryId: id },
})
.json<DocumentEntry>();
}
}
2 changes: 1 addition & 1 deletion src/cws/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ export async function moveEntry(entry: EntryIdLike, path: Path) {
DestinationParentPath: normalizePath(path),
},
});
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,4 @@ interface ReportEntry {
'Trellis Document Type': string;
'Trellis File ID': string; // The actual binary doc synced,
}
*/
*/
2 changes: 1 addition & 1 deletion src/lfdynamic-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,4 @@ export interface SAPVendor {

await main();
// Const rows = grabVendors();
// console.log(rows);
// console.log(rows);
2 changes: 1 addition & 1 deletion src/scripts/lf/clean-dups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@ function trashPath(path: string): `/${string}` {
return `/${parts.join('/')}`;
}

process.exit();
process.exit();
2 changes: 1 addition & 1 deletion src/scripts/lf/delete-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ const entryId = Number(argv[2]); // As unknown as EntryId;
const entry = await retrieveEntry(entryId);

// @awlayton: your auto format rules makes this __really__ ugly
await (entry.Type === 'Folder' ? deleteFolder(entry) : deleteDocument(entry));
await (entry.Type === 'Folder' ? deleteFolder(entry) : deleteDocument(entry));
2 changes: 1 addition & 1 deletion src/scripts/lf/find-zero-sized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ async function findZeroSized(root: FolderEntry) {
}
}

process.exit();
process.exit();
2 changes: 1 addition & 1 deletion src/scripts/lf/list-by-doc-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ for await (const partner of partners) {
}

console.log('DONE');
process.exit();
process.exit();
2 changes: 1 addition & 1 deletion src/scripts/lf/move-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ if (argv.length !== 4) {
const entryId = Number(argv[2]); // As unknown as EntryId;
const path = argv[3] as unknown as `/${string}`;

await moveEntry(entryId, path);
await moveEntry(entryId, path);
2 changes: 1 addition & 1 deletion src/scripts/lf/trash-by-doc-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ function trashPath(path: string): `/${string}` {
const parts = path.split('\\').slice(2, -1);
parts[0] = 'trellis-trash';
return `/${parts.join('/')}`;
}
}
2 changes: 1 addition & 1 deletion src/scripts/old/move-zendesk-tickets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ for await (const partner of partners) {
}
}

process.exit();
process.exit();
2 changes: 1 addition & 1 deletion src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,4 @@ export async function sync(
log.error(error_, `Could not sync document ${doc._id}.`);
throw error_;
}
}
}
2 changes: 1 addition & 1 deletion src/transformers/coi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ export function coiMetadata(document: Resource): Metadata {
*/

return metadata;
}
}
2 changes: 1 addition & 1 deletion src/transformers/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ const metadataMappings = {
// 'failures':
// 'reaudit_date':
// 'scheme':
} as const;
} as const;
2 changes: 1 addition & 1 deletion src/transformers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,4 @@ const transformers = new Map<string, Transformers>([
'application/vnd.zendesk.ticket.1+json',
{ doc: ticketMetadata, vdoc: ticketVdocMetadata },
],
]);
]);
2 changes: 1 addition & 1 deletion src/transformers/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,4 @@ export interface SideConversationEvent {
| undefined;
updates: Record<string, unknown>;
ticket_id: number;
}
}
2 changes: 1 addition & 1 deletion src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ export const docTypesTree: Tree = {
},
},
},
};
};
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

interface ObjectConstructor {
entries<K extends string, V>(object: Record<K, V>): Array<[K, V]>;
}
}
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,4 @@ export interface Metadata {
'Locations'?: string[];
'Original Filename'?: string;
'Ticket Comment Number'?: string;
}
}
58 changes: 37 additions & 21 deletions test/filingWorkflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,67 @@

import test from 'ava';

import {
filingWorkflow,
getFormattedDate
} from '../dist/utils.js';
import { filingWorkflow, getFormattedDate } from '../dist/utils.js';

test('filing workflow', (t) => {
let date = new Date();
let ticketMeta = {
Entity: 'Bob Foods, LLC',
'Entity': 'Bob Foods, LLC',
'Document Type': 'Zendesk Ticket',
'Document Date': getFormattedDate(date),
'Share Mode': 'Shared to Smithfield',
'Expiration Date': getFormattedDate(date),
'Zendesk Ticket ID': '1115',
Products: ['Honey Glaze', "Brown Sugar Glaze"],
Locations: ['Location A', 'Location B'],
'Original Filename': "RandFilename-2.xyz",
}
'Products': ['Honey Glaze', 'Brown Sugar Glaze'],
'Locations': ['Location A', 'Location B'],
'Original Filename': 'RandFilename-2.xyz',
};
let result = filingWorkflow(ticketMeta);

t.is(result.filename, 'RandFilename-2.xyz', 'Zendesk Ticket handling')
t.is(result.path, '/trellis/trading-partners/Bob Foods, LLC/Shared to Smithfield/Zendesk Ticket/2024-09/Ticket1115', 'Zendesk Ticket handling')
t.is(result.filename, 'RandFilename-2.xyz', 'Zendesk Ticket handling');
t.is(
result.path,
'/trellis/trading-partners/Bob Foods, LLC/Shared to Smithfield/Zendesk Ticket/2024-09/Ticket1115',
'Zendesk Ticket handling',
);

let docMeta = {
Entity: 'Bob Foods, LLC',
'Entity': 'Bob Foods, LLC',
'Document Type': 'Certificate of Insurance',
'Document Date': getFormattedDate(date),
'Share Mode': 'Shared to Smithfield',
'Expiration Date': getFormattedDate(date),
Products: ['Honey Glaze', "Brown Sugar Glaze"],
Locations: ['Location A', 'Location B'],
'Original Filename': "RandFilename-2.xyz",
}
'Products': ['Honey Glaze', 'Brown Sugar Glaze'],
'Locations': ['Location A', 'Location B'],
'Original Filename': 'RandFilename-2.xyz',
};
result = filingWorkflow(docMeta);
let expDate = date.toISOString().split('T')[0];

t.is(result.filename, `[Certificate of Insurance][Bob Foods, LLC][EXP_${expDate}][Multi-Location][Multi-Product]`, 'Non-ticket filename invalid')
t.is(result.path, '/trellis/trading-partners/Bob Foods, LLC/Shared to Smithfield/Certificate of Insurance', 'Non-ticket path invalid')
t.is(
result.filename,
`[Certificate of Insurance][Bob Foods, LLC][EXP_${expDate}][Multi-Location][Multi-Product]`,
'Non-ticket filename invalid',
);
t.is(
result.path,
'/trellis/trading-partners/Bob Foods, LLC/Shared to Smithfield/Certificate of Insurance',
'Non-ticket path invalid',
);

docMeta.Products.pop();
docMeta.Locations.pop();
//@ts-expect-error no likey delete
delete docMeta['Expiration Date'];
result = filingWorkflow(docMeta);
t.is(result.filename, `[Certificate of Insurance][Bob Foods, LLC][Location A][Honey Glaze][Certificate of Insurance]`, 'Non-ticket filename invalid')
t.is(result.path, '/trellis/trading-partners/Bob Foods, LLC/Shared to Smithfield/Certificate of Insurance', 'Non-ticket path invalid')
t.is(
result.filename,
`[Certificate of Insurance][Bob Foods, LLC][Location A][Honey Glaze][Certificate of Insurance]`,
'Non-ticket filename invalid',
);
t.is(
result.path,
'/trellis/trading-partners/Bob Foods, LLC/Shared to Smithfield/Certificate of Insurance',
'Non-ticket path invalid',
);
});

0 comments on commit 40c19fe

Please sign in to comment.