Skip to content

Commit

Permalink
chore: move from public/private factory functions to unauthenticated/…
Browse files Browse the repository at this point in the history
…authenticated
  • Loading branch information
dtfiedler committed Sep 6, 2023
1 parent b56216e commit b1559f7
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The SDK is available in both CommonJS and ESM formats and is compatible with bun
```javascript
import { TurboFactory } from '@ardrive/turbo-sdk/web';

const turbo = TurboFactory.public({});
const turbo = TurboFactory.unauthenticated({});
const rates = await turbo.getFiatRates();
```

Expand All @@ -50,7 +50,7 @@ const rates = await turbo.getFiatRates();
```html
<script src="https://cdn.jsdelivr.net/npm/@ardrive/turbo-sdk"></script>
<script>
const turbo = TurboFactory.public({});
const turbo = TurboFactory.unauthenticated({});
const rates = await turbo.getFiatRates();
</script>
```
Expand All @@ -62,7 +62,7 @@ const rates = await turbo.getFiatRates();
```javascript
const { TurboFactory } = require('@ardrive/turbo-sdk/node');

const turbo = TurboFactory.public({});
const turbo = TurboFactory.unauthenticated({});
const rates = await turbo.getFiatRates();
```

Expand All @@ -71,7 +71,7 @@ const rates = await turbo.getFiatRates();
```javascript
import { TurboFactory } from '@ardrive/turbo-sdk/node';

const turbo = TurboFactory.public({});
const turbo = TurboFactory.unauthenticated({});
const rates = await turbo.getFiatRates();
```

Expand Down
4 changes: 2 additions & 2 deletions examples/node/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Fetching rates using an unauthenticated Turbo client.
*/
const turbo = TurboFactory.public();
const turbo = TurboFactory.unauthenticated();
const rates = await turbo.getFiatRates();
console.log('Fetched rates:', JSON.stringify(rates, null, 2));

Expand All @@ -34,7 +34,7 @@
/**
* Use the arweave key to create an authenticated turbo client
*/
const turboAuthClient = TurboFactory.private({ privateKey: jwk });
const turboAuthClient = TurboFactory.authenticated({ privateKey: jwk });

/**
* Fetch the balance for the private key.
Expand Down
4 changes: 2 additions & 2 deletions examples/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
/**
* Fetching rates using an unauthenticated Turbo client.
*/
const turbo = TurboFactory.public();
const turbo = TurboFactory.unauthenticated();
const rates = await turbo.getFiatRates();
console.log('Fetched rates:', JSON.stringify(rates, null, 2));

Expand All @@ -32,7 +32,7 @@ import {
const arweave = new Arweave.init();
const jwk = await Arweave.crypto.generateJWK();
const address = await arweave.wallets.jwkToAddress(jwk);
const turboAuthClient = TurboFactory.private({ privateKey: jwk });
const turboAuthClient = TurboFactory.authenticated({ privateKey: jwk });
const balance = await turboAuthClient.getBalance();
console.log(
'Balance:',
Expand Down
2 changes: 1 addition & 1 deletion examples/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1>Upload File</h1>
});
const jwk = await arweave.crypto.generateJWK();
const address = await arweave.wallets.jwkToAddress(jwk);
const turbo = TurboFactory.private({
const turbo = TurboFactory.authenticated({
privateKey: jwk,
});

Expand Down
2 changes: 1 addition & 1 deletion src/common/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { TurboUnauthenticatedClient } from './turbo.js';
import { TurboUnauthenticatedUploadService } from './upload.js';

export class TurboBaseFactory {
static public({
static unauthenticated({
paymentServiceConfig = {},
uploadServiceConfig = {},
}: TurboPublicConfiguration = {}) {
Expand Down
2 changes: 1 addition & 1 deletion src/node/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { TurboPrivateConfiguration } from '../types/index.js';
import { TurboNodeArweaveSigner } from './signer.js';

export class TurboFactory extends TurboBaseFactory {
static private({
static authenticated({
privateKey,
paymentServiceConfig = {},
uploadServiceConfig = {},
Expand Down
2 changes: 1 addition & 1 deletion src/web/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { TurboPrivateConfiguration } from '../types/index.js';
import { TurboWebArweaveSigner } from './signer.js';

export class TurboFactory extends TurboBaseFactory {
static private({
static authenticated({
privateKey,
paymentServiceConfig = {},
uploadServiceConfig = {},
Expand Down
10 changes: 5 additions & 5 deletions tests/turbo.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import {
TurboAuthenticatedClient,
TurboUnauthenticatedClient,
} from '../src/common/turbo.js';
import { TurboFactory } from '../src/node/index.js';
import { TurboFactory } from '../src/node/factory.js';
import { JWKInterface } from '../src/types/index.js';
import { jwkToPublicArweaveAddress } from '../src/utils/base64.js';

describe('Node environment', () => {
describe('TurboFactory', () => {
it('should return a TurboUnauthenticatedClient when running in Node environment and not provided a privateKey', () => {
const turbo = TurboFactory.public({});
const turbo = TurboFactory.unauthenticated({});
expect(turbo).to.be.instanceOf(TurboUnauthenticatedClient);
});
it('should return a TurboAuthenticatedClient when running in Node environment and provided a privateKey', async () => {
const jwk = await Arweave.crypto.generateJWK();
const turbo = TurboFactory.private({ privateKey: jwk });
const turbo = TurboFactory.authenticated({ privateKey: jwk });
expect(turbo).to.be.instanceOf(TurboAuthenticatedClient);
});
});
Expand All @@ -30,7 +30,7 @@ describe('Node environment', () => {
let turbo: TurboUnauthenticatedClient;

before(() => {
turbo = TurboFactory.public({});
turbo = TurboFactory.unauthenticated({});
});

it('getFiatRates()', async () => {
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('Node environment', () => {

before(async () => {
jwk = await Arweave.crypto.generateJWK();
turbo = TurboFactory.private({
turbo = TurboFactory.authenticated({
privateKey: jwk,
});
});
Expand Down
8 changes: 4 additions & 4 deletions tests/turbo.web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ describe('Browser environment', () => {

describe('TurboFactory', () => {
it('should be a TurboUnauthenticatedClient running in the browser and not provided a privateKey', () => {
const turbo = TurboFactory.public({});
const turbo = TurboFactory.unauthenticated({});
expect(turbo).to.be.instanceOf(TurboUnauthenticatedClient);
});

it('should be a TurboAuthenticatedClient running in the browser and provided a privateKey', async () => {
const jwk = await Arweave.crypto.generateJWK();
const turbo = TurboFactory.private({ privateKey: jwk });
const turbo = TurboFactory.authenticated({ privateKey: jwk });
expect(turbo).to.be.instanceOf(TurboUnauthenticatedClient);
});
});
Expand All @@ -38,7 +38,7 @@ describe('Browser environment', () => {
let turbo: TurboUnauthenticatedClient;

before(() => {
turbo = TurboFactory.public({});
turbo = TurboFactory.unauthenticated({});
});

describe('unauthenticated requests', () => {
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('Browser environment', () => {
let jwk: JWKInterface;
before(async () => {
jwk = await Arweave.crypto.generateJWK();
turbo = TurboFactory.private({ privateKey: jwk });
turbo = TurboFactory.authenticated({ privateKey: jwk });
});

it('getBalance()', async () => {
Expand Down

0 comments on commit b1559f7

Please sign in to comment.