Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ but in general, the steps are
nano users/foobar/var/lib/storage.json

# connect platform `bla` to user `foobar`
./fairpost.js @foobar setup-platform --platform=bla
./fairpost.js @foobar connect-platform --platform=bla

```

Expand Down Expand Up @@ -137,7 +137,7 @@ Access and refresh tokens for various platforms may
expire sooner or later. Before you do anything, try
`fairpost.js @userid refresh-platforms`. Eventually, even
refresh tokens may expire, and you will have to run
`fairpost.js @userid setup-platform --platform=bla` again
`fairpost.js @userid connect-platform --platform=bla` again
to get a new pair of tokens.


Expand All @@ -156,7 +156,7 @@ fairpost: @userid get-platform --platform=xxx
fairpost: @userid put-platform --platform=xxx << payload
fairpost: @userid edit-platform --platform=xxx (cli only)
fairpost: @userid get-platforms [--platforms=xxx,xxx]
fairpost: @userid setup-platform --platform=xxx
fairpost: @userid connect-platform --platform=xxx
fairpost: @userid test-platform --platform=xxx
fairpost: @userid test-platforms [--platforms=xxx,xxx]
fairpost: @userid refresh-platform --platform=xxx
Expand Down
4 changes: 2 additions & 2 deletions docs/Facebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tokens, you can turn on Live mode and start posting.
- go to https://developers.facebook.com/
- select your app, edit it
- set App Mode to 'dev'
- call `./fairpost.js @userid setup-platform --platform=facebook`
- call `./fairpost.js @userid connect-platform --platform=facebook`
- follow instructions from the command line

### Test the platform
Expand Down Expand Up @@ -81,7 +81,7 @@ One fairpost user can only manage one page. If you create a second user, you can
- go to https://developers.facebook.com/
- select your app, edit it
- set App Mode to 'dev'
- call `./fairpost.js @foo setup-platform --platform=facebook`
- call `./fairpost.js @foo connect-platform --platform=facebook`
- follow instructions from the command line
- put your app back in live mode

Expand Down
4 changes: 2 additions & 2 deletions docs/Instagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ tokens, you can turn on Live mode and start posting.
- go to https://developers.facebook.com/
- select your app, edit it
- set App Mode to 'dev'
- call `./fairpost.js @userid setup-platform --platform=instagram`
- call `./fairpost.js @userid connect-platform --platform=instagram`
- follow instructions from the command line

### Test the platform
Expand Down Expand Up @@ -94,7 +94,7 @@ One fairpost user can only manage one page. If you create a second user, you can
- go to https://developers.facebook.com/
- select your app, edit it
- set App Mode to 'dev'
- call `./fairpost.js @foo setup-platform --platform=instagram`
- call `./fairpost.js @foo connect-platform --platform=instagram`
- follow instructions from the command line
- put your app back in live mode

Expand Down
4 changes: 2 additions & 2 deletions docs/LinkedIn.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ https://www.linkedin.com/developers/apps/new
This token last for 60 days and should be refreshed.
The refresh token (if given) lasts for 1 year.

- call `./fairpost.js @userid setup-platform --platform=linkedin`
- call `./fairpost.js @userid connect-platform --platform=linkedin`
- follow instructions from the command line

### Test the platform
Expand All @@ -50,7 +50,7 @@ One fairpost user can only manage one page. If you create a second user, you can

### Get an OAuth2 Access Token for your other page

- call `./fairpost.js @foo setup-platform --platform=linkedin`
- call `./fairpost.js @foo connect-platform --platform=linkedin`
- follow instructions from the command line

### Test the other installation
Expand Down
8 changes: 4 additions & 4 deletions docs/NewPlatform.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ and party.
This method allows you to call `fairpost.js test-platform --platform=foobar`.
You can return anything.

#### FooBar.setup()
#### FooBar.connect()

This method allows you to call `fairpost.js setup-platform --platform=foobar`,
This method allows you to call `fairpost.js connect-platform --platform=foobar`,
usually to get the access tokens and save them in Storage.

#### FooBar.refresh()
Expand Down Expand Up @@ -215,7 +215,7 @@ import {

Another good approach to refactor is to take the Authentication
flow out of your platform into a separate `FooBar/FooBarAuth.ts`.
Add a method `setup()` and link your `Foobar.setup()` there.
Add a method `connect()` and link your `Foobar.connect()` there.
Optionally add a method `refresh()` and link your `Foobar.refresh()` there.
Store the access tokens in `auth` Storage, so you can access them
in your platform class.
Expand All @@ -240,7 +240,7 @@ export default class FooBarAuth {
/**
* Set up FooBar platform
*/
async setup() {
async connect() {
const code = await this.requestCode();
const tokens = await this.exchangeCode(code);
await this.store(tokens);
Expand Down
2 changes: 1 addition & 1 deletion docs/Reddit.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

This token only lasts for 24 hours and should be refreshed.

- call `./fairpost.js @userid setup-platform --platform=reddit`
- call `./fairpost.js @userid connect-platform --platform=reddit`
- follow instructions from the command line


Expand Down
4 changes: 2 additions & 2 deletions docs/Twitter.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ keys will not be needed anymore.

This token should last forever (?)

- call `./fairpost.js @userid setup-platform --platform=twitter`
- call `./fairpost.js @userid connect-platform --platform=twitter`
- follow instructions from the command line

### Test the platform
Expand All @@ -60,7 +60,7 @@ account and requires you to specify an 'additional_owner' for the uploaded media

### Get an OAuth2 Access Token for your other page

- call `./fairpost.js @foo setup-platform --platform=twitter`
- call `./fairpost.js @foo connect-platform --platform=twitter`
- follow instructions from the command line

### Test the other installation
Expand Down
4 changes: 2 additions & 2 deletions docs/Youtube.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ To have Fairpost publish **public** videos, your app has to be audited
This token last for a few hours and should be refreshed.
The refresh token (if given) lasts until it is revoked.

- call `./fairpost.js @userid setup-platform --platform=youtube`
- call `./fairpost.js @userid connect-platform --platform=youtube`
- follow instructions from the command line

### Test the platform
Expand All @@ -70,7 +70,7 @@ The refresh token (if given) lasts until it is revoked.

### Get an OAuth2 Access Token for your other page

- call `./fairpost.js @foo setup-platform --platform=youtube`
- call `./fairpost.js @foo connect-platform --platform=youtube`
- follow instructions from the command line

### Test the other installation
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fairpost",
"version": "3.0.0",
"version": "4.0.0",
"type": "module",
"engines": {
"node": "22.17.0"
Expand Down
6 changes: 3 additions & 3 deletions src/models/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class Platform {
}

/**
* setup
* connect
*
* Set the platform up. Get the required keys and tokens.
* This may involve starting a webserver and/or communicating
Expand All @@ -55,9 +55,9 @@ export default class Platform {
* @returns - any object
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setup(operator?: Operator, payload?: object): Promise<unknown> {
async connect(operator?: Operator, payload?: object): Promise<unknown> {
throw this.user.log.error(
"No setup implemented for " +
"No connect implemented for " +
this.id +
". Read the docs in the docs folder.",
);
Expand Down
10 changes: 5 additions & 5 deletions src/platforms/Bluesky/Bluesky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ export default class Bluesky extends Platform {
}

/** @inheritdoc */
async setup(operator: Operator, payload?: object) {
async connect(operator: Operator, payload?: object) {
if (operator.ui === "cli") {
await this.auth.setupCli();
await this.auth.connectCli();
return await this.test();
}
if (operator.ui === "api") {
if (!payload) {
throw this.user.log.error("Bluesky setup requires a payload");
throw this.user.log.error("Bluesky connect requires a payload");
}
await this.auth.setupApi(payload);
await this.auth.connectApi(payload);
return await this.test();
}
throw this.user.log.error(
`${this.id} setup: ui ${operator.ui} not supported`,
`${this.id} connect: ui ${operator.ui} not supported`,
);
}

Expand Down
16 changes: 11 additions & 5 deletions src/platforms/Bluesky/BlueskyAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class BlueskyAuth {
* In 2025, this uses a service, user handle, app password
*/

public async setupCli() {
public async connectCli() {
const reader = readline.createInterface({
input: process.stdin,
output: process.stdout,
Expand All @@ -28,21 +28,27 @@ export default class BlueskyAuth {
};
const currentid = this.user.data.get("settings", "BLUESKY_IDENTIFIER", "");
if (!currentid) {
throw this.user.log.error("BlueskyAuth:setupCli - set identifier first");
throw this.user.log.error(
"BlueskyAuth:connectCli - set identifier first",
);
}
tokens.password = await reader.question(`BlueSky app password: `);
reader.close();
await this.store(tokens);
console.log("Credentials stored.");
}

public async setupApi(payload: { password?: string }) {
public async connectApi(payload: { password?: string }) {
const currentid = this.user.data.get("settings", "BLUESKY_IDENTIFIER", "");
if (!currentid) {
throw this.user.log.error("BlueskyAuth:setupApi - set identifier first");
throw this.user.log.error(
"BlueskyAuth:connectApi - set identifier first",
);
}
if (!payload.password) {
throw this.user.log.error("BlueskyAuth:setupApi - app password missing");
throw this.user.log.error(
"BlueskyAuth:connectApi - app password missing",
);
}
await this.store({
password: payload.password,
Expand Down
10 changes: 5 additions & 5 deletions src/platforms/Facebook/Facebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ export default class Facebook extends Platform {
}

/** @inheritdoc */
async setup(operator: Operator, payload?: object) {
async connect(operator: Operator, payload?: object) {
if (operator.ui === "cli") {
await this.auth.setupCli();
await this.auth.connectCli();
return await this.test();
}
if (operator.ui === "api") {
if (!payload) {
throw this.user.log.error("Setup via api requires a payload");
throw this.user.log.error("Connect via api requires a payload");
}
return this.auth.setupApi(payload);
return this.auth.connectApi(payload);
}
throw this.user.log.error(
`${this.id} setup: ui ${operator.ui} not supported`,
`${this.id} connect: ui ${operator.ui} not supported`,
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/platforms/Facebook/FacebookAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class FacebookAuth {
this.user = user;
}

async setupCli() {
async connectCli() {
const code = await this.requestCode(
this.user.data.get("app", "FACEBOOK_APP_ID"),
);
Expand All @@ -40,8 +40,8 @@ export default class FacebookAuth {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async setupApi(payload: object) {
throw this.user.log.error("FacebookAuth:setupApi - not implemented");
public async connectApi(payload: object) {
throw this.user.log.error("FacebookAuth:connectApi - not implemented");
}

protected async requestCode(clientId: string): Promise<string> {
Expand Down
10 changes: 5 additions & 5 deletions src/platforms/Instagram/Instagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ export default class Instagram extends Platform {
}

/** @inheritdoc */
async setup(operator: Operator, payload?: object) {
async connect(operator: Operator, payload?: object) {
if (operator.ui === "cli") {
await this.auth.setupCli();
await this.auth.connectCli();
return await this.test();
}
if (operator.ui === "api") {
if (!payload) {
throw this.user.log.error("Setup via api requires a payload");
throw this.user.log.error("Connect via api requires a payload");
}
return this.auth.setupApi(payload);
return this.auth.connectApi(payload);
}
throw this.user.log.error(
`${this.id} setup: ui ${operator.ui} not supported`,
`${this.id} connect: ui ${operator.ui} not supported`,
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/platforms/Instagram/InstagramAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class InstagramAuth extends FacebookAuth {
super(user);
}

async setup() {
async connect() {
const code = await this.requestCode(
this.user.data.get("app", "INSTAGRAM_APP_ID"),
);
Expand All @@ -30,8 +30,8 @@ export default class InstagramAuth extends FacebookAuth {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async setupApi(payload: object) {
throw this.user.log.error("InstagramAuth:setupApi - not implemented");
public async connectApi(payload: object) {
throw this.user.log.error("InstagramAuth:connectApi - not implemented");
}

protected async requestCode(clientId: string): Promise<string> {
Expand Down
10 changes: 5 additions & 5 deletions src/platforms/LinkedIn/LinkedIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ export default class LinkedIn extends Platform {
}

/** @inheritdoc */
async setup(operator: Operator, payload?: object) {
async connect(operator: Operator, payload?: object) {
if (operator.ui === "cli") {
await this.auth.setupCli();
await this.auth.connectCli();
return await this.test();
}
if (operator.ui === "api") {
if (!payload) {
throw this.user.log.error("Setup via api requires a payload");
throw this.user.log.error("Connect via api requires a payload");
}
const result = await this.auth.setupApi(payload);
const result = await this.auth.connectApi(payload);
const ready = "ready" in result && result.ready;
if (!ready) return result;
return {
Expand All @@ -81,7 +81,7 @@ export default class LinkedIn extends Platform {
}

throw this.user.log.error(
`${this.id} setup: ui ${operator.ui} not supported`,
`${this.id} connect: ui ${operator.ui} not supported`,
);
}

Expand Down
Loading