Skip to content

Commit f17a010

Browse files
feat: rename project to athena-classifier-sdk and update package details
- Updated project name and description in package.json. - Added new dependencies for authentication and image processing. - Introduced AuthenticationManager for handling OAuth authentication. - Created hashing utility to compute MD5 and SHA1 hashes while resizing images. - Refactored main.ts to integrate new authentication and hashing functionalities. - Updated TypeScript configuration for better module handling and declaration generation.
1 parent 1bd6df8 commit f17a010

11 files changed

Lines changed: 1023 additions & 122 deletions

File tree

.github/FUNDING.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ build/
2626
.eslintcache
2727

2828
# Misc
29-
.DS_Store
29+
.DS_Store
30+
.env

__tests__/unit/main.test.ts

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,94 @@
1-
import { describe, it, afterEach, beforeEach, vi, expect } from 'vitest';
2-
import { classifyImage, computeHashesFromStream, ClassifyImageOptions } from '../../src/main.js';
3-
4-
1+
import { describe, it,} from 'vitest';
2+
import { ClassifierSdk, ClassifyImageOptions, ClassifyResponse, ImageFormat } from '../../src/main';
53
import fs from 'fs';
4+
import { randomUUID } from 'crypto';
5+
6+
describe('classifierHelper', () => {
7+
it('should listDeployments and return responses using stubbed api)', async ({expect}) => {
8+
// This is a smoke test. You must have a running gRPC server at localhost:50051 for this to pass.
9+
// You may want to mock the gRPC client for true unit testing.
10+
const sdk = new ClassifierSdk({
11+
deploymentId: process.env.VITE_ATHENA_DEPLOYMENT_ID,
12+
affiliate: process.env.VITE_ATHENA_AFFILIATE,
13+
authentication: {
14+
issuerUrl: 'https://crispthinking.auth0.com/',
15+
clientId: process.env.VITE_ATHENA_CLIENT_ID,
16+
clientSecret: process.env.VITE_ATHENA_CLIENT_SECRET,
17+
scope: 'manage:classify'
18+
}
19+
});
20+
// This will fail if no server is running, but will exercise the code path.
21+
let error: any = null;
22+
try {
23+
const responses = await sdk.listDeployments();
24+
expect(Array.isArray(responses)).toBe(true);
25+
} catch (err) {
26+
error = err;
27+
}
28+
// Assert error is unset
29+
expect(error).toBeNull();
30+
}, { timeout: 10000 })
31+
});
632

733
describe('classifyImage function', () => {
8-
it('should classify Steamboat-willie.jpg and return responses (integration smoke test)', async () => {
34+
it('should classify Steamboat-willie.jpg and return responses (integration smoke test)', async ({expect}) => {
935
// This is a smoke test. You must have a running gRPC server at localhost:50051 for this to pass.
1036
// You may want to mock the gRPC client for true unit testing.
1137
const imagePath = __dirname + '/Steamboat-willie.jpg';
38+
const sdk = new ClassifierSdk({
39+
deploymentId: process.env.VITE_ATHENA_DEPLOYMENT_ID,
40+
affiliate: process.env.VITE_ATHENA_AFFILIATE,
41+
authentication: {
42+
issuerUrl: 'https://crispthinking.auth0.com/',
43+
clientId: process.env.VITE_ATHENA_CLIENT_ID,
44+
clientSecret: process.env.VITE_ATHENA_CLIENT_SECRET,
45+
scope: 'manage:classify'
46+
}
47+
});
48+
49+
const correlationId = randomUUID();
50+
51+
// Create a promise to wrap the event emitter event 'data'
52+
const promise = new Promise<ClassifyResponse>((resolve, reject) => {
53+
sdk.once('data', (data) => {
54+
const byCorrelationId = data.outputs.filter(o => o.correlationId === correlationId);
55+
if (byCorrelationId.length > 0) {
56+
resolve(data);
57+
}
58+
sdk.close();
59+
});
60+
sdk.once('error', (err) => {
61+
reject(err);
62+
});
63+
});
64+
65+
// This will fail if no server is running, but will exercise the code path.
66+
let error: any = undefined;
67+
68+
await sdk.open();
69+
1270
const imageStream = fs.createReadStream(imagePath);
1371
const options: ClassifyImageOptions = {
1472
imageStream,
15-
deploymentId: 'test-deployment',
16-
affiliate: 'test-affiliate',
17-
correlationId: 'test-correlation',
18-
// encoding, format, grpcAddress use defaults
73+
format: ImageFormat.PNG,
74+
correlationId
1975
};
20-
// This will fail if no server is running, but will exercise the code path.
21-
let error: any = null;
2276
try {
23-
const responses = await classifyImage(options);
24-
expect(Array.isArray(responses)).toBe(true);
77+
await sdk.sendClassifyRequest(options);
2578
} catch (err) {
2679
error = err;
2780
}
81+
82+
// Wait for classifier to process some data....
83+
const first = await promise;
84+
85+
expect(first).toBeDefined();
86+
87+
const byCorrelationId = first.outputs.filter(o => o.correlationId === correlationId);
88+
89+
expect(byCorrelationId.length).toBeGreaterThan(0);
90+
2891
// Accept either a successful call or a connection error (for CI/dev convenience)
29-
if (error) {
30-
expect(error.message).toMatch(/connect|unavailable|ECONNREFUSED|14/);
31-
}
32-
});
92+
expect(error).toBeUndefined();
93+
}, { timeout: 120000 });
3394
});

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import tseslint from 'typescript-eslint';
99
// You should change it to your needs following the documentation.
1010
export default tseslint.config(
1111
{
12-
ignores: ['**/build/**', '**/tmp/**', '**/coverage/**'],
12+
ignores: ['**/build/**', '**/__tests__/**', '**/tmp/**', '**/coverage/**', 'src/athena/**'],
1313
},
1414
eslint.configs.recommended,
1515
eslintConfigPrettier,

0 commit comments

Comments
 (0)