Skip to content

Commit

Permalink
fix: Merge branch 'alpha' into alpha-deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Sep 7, 2023
2 parents 476e864 + 5f37942 commit 699706b
Show file tree
Hide file tree
Showing 59 changed files with 9,689 additions and 5,373 deletions.
18 changes: 0 additions & 18 deletions packages/examples/sdk-backend-node/.eslintrc.json

This file was deleted.

24 changes: 15 additions & 9 deletions packages/examples/sdk-backend-node/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ git clone https://github.com/ethereum-push-notification-service/push-sdk.git
cd push-sdk
yarn install
```
***Note*** - We are using `yarn` and **strongly** advise to use yarn 1.x to avoid any NPM issues.

## Setting up the SDK-Backend-Node
**_Note_** - We are using `yarn` and **strongly** advise to use yarn 1.x to avoid any NPM issues.

## Setting up the SDK-Backend-Node

1. Navigate to the `packages/examples/sdk-backend-node` directory.
```bash
cd packages/examples/sdk-backend-node
```
2. Set up your environment variables by creating a `.env` file based on the provided `.env.sample` file.
3. Install the node dependencies
```bash
yarn install
```

## Running the SDK-Backend-Node
### By GUI (preferred)
1. Click on the `NX console` extension icon in the VSCode sidebar.
2. Click on the `serve` target execute icon under `examples-sdk-backend-node`
## Running the SDK-Backend-Node

### By CLI
1. Navigate to the root level of push-sdk repository.
2. Run `yarn nx serve packages/examples/sdk-backend-node`
```bash
yarn start
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ const nftChainId1 = process.env.NFT_CHAIN_ID_1;
const nftContractAddress1 = process.env.NFT_CONTRACT_ADDRESS_1;
const nftTokenId1 = process.env.NFT_TOKEN_ID_1;
const nftHolderWalletPrivatekey1 = process.env.NFT_HOLDER_WALLET_PRIVATE_KEY_1;
const nftSigner1 = new ethers.Wallet(`0x${nftHolderWalletPrivatekey1}`);
const nftSigner1 = nftHolderWalletPrivatekey1
? new ethers.Wallet(`0x${nftHolderWalletPrivatekey1}`)
: undefined;
const nftAccount1 = `nft:eip155:${nftChainId1}:${nftContractAddress1}:${nftTokenId1}`;
const nftProfilePassword1 = process.env.NFT_PROFILE_PASSWORD_1;
const nftChainId2 = process.env.NFT_CHAIN_ID_2;
const nftContractAddress2 = process.env.NFT_CONTRACT_ADDRESS_2;
const nftTokenId2 = process.env.NFT_TOKEN_ID_2;
const nftHolderWalletPrivatekey2 = process.env.NFT_HOLDER_WALLET_PRIVATE_KEY_2;
const nftSigner2 = new ethers.Wallet(`0x${nftHolderWalletPrivatekey2}`);
const nftSigner2 = nftHolderWalletPrivatekey2
? new ethers.Wallet(`0x${nftHolderWalletPrivatekey2}`)
: undefined;
const nftAccount2 = `nft:eip155:${nftChainId2}:${nftContractAddress2}:${nftTokenId2}`;
const nftProfilePassword2 = process.env.NFT_PROFILE_PASSWORD_2;
const nftAccount3 = `nft:eip155:${nftChainId2}:${nftContractAddress2}:10`;
Expand All @@ -46,6 +50,29 @@ const groupDescription = uniqueNamesGenerator({
const groupImage =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAvklEQVR4AcXBsW2FMBiF0Y8r3GQb6jeBxRauYRpo4yGQkMd4A7kg7Z/GUfSKe8703fKDkTATZsJsrr0RlZSJ9r4RLayMvLmJjnQS1d6IhJkwE2bT13U/DBzp5BN73xgRZsJMmM1HOolqb/yWiWpvjJSUiRZWopIykTATZsJs5g+1N6KSMiO1N/5DmAkzYTa9Lh6MhJkwE2ZzSZlo7xvRwson3txERzqJhJkwE2bT6+JhoKTMJ2pvjAgzYSbMfgDlXixqjH6gRgAAAABJRU5ErkJggg==';

const skipExample = () => {
const requiredEnvVars = [
'NFT_CHAIN_ID_1',
'NFT_CONTRACT_ADDRESS_1',
'NFT_TOKEN_ID_1',
'NFT_HOLDER_WALLET_PRIVATE_KEY_1',
'NFT_PROFILE_PASSWORD_1',
'NFT_CHAIN_ID_2',
'NFT_CONTRACT_ADDRESS_2',
'NFT_TOKEN_ID_2',
'NFT_HOLDER_WALLET_PRIVATE_KEY_2',
'NFT_PROFILE_PASSWORD_2',
];

for (const envVar of requiredEnvVars) {
if (!process.env[envVar]) {
return true; // Skip the example if any of the required env vars is missing
}
}

return false; // All required env vars are present, don't skip the example
};

// Push Chat - Run Chat Use cases
export const runNFTChatUseCases = async (): Promise<void> => {
console.log(`
Expand All @@ -55,6 +82,12 @@ export const runNFTChatUseCases = async (): Promise<void> => {
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ████ ██ ██ ██████ ██ ██ ██ ██ ██
`);

if (skipExample()) {
console.log('Skipping examples as required env vars are missing');
return;
}

console.log('PushAPI.user.create');
await PushAPI_nft_user_create();

Expand Down Expand Up @@ -113,14 +146,14 @@ async function PushAPI_nft_user_create(silent = !showAPIResponse) {
account: nftAccount1,
signer: nftSigner1,
env: env as ENV,
additionalMeta: { NFTPGP_V1: { password: nftProfilePassword1 } },
additionalMeta: { NFTPGP_V1: { password: nftProfilePassword1 as string } },
});

const user2 = await PushAPI.user.create({
account: nftAccount2,
signer: nftSigner2,
env: env as ENV,
additionalMeta: { NFTPGP_V1: { password: nftProfilePassword2 } },
additionalMeta: { NFTPGP_V1: { password: nftProfilePassword2 as string } },
});

console.log('PushAPI_nft_user_create | Response - 200 OK');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ENV } from './types';
dotenv.config();

export const config = {
env: process.env.PUSH_NODE_NETWORK as ENV, // choose ENV.STAGING or ENV.PROD
env: process.env.PUSH_NODE_NETWORK
? (process.env.PUSH_NODE_NETWORK as ENV)
: ('staging' as ENV), // choose ENV.STAGING or ENV.PROD
showAPIResponse: process.env.SHOW_API_RESPONSE === 'true' ? true : false, // choose to show or hide API responses
};
16 changes: 0 additions & 16 deletions packages/examples/sdk-backend-node/jest.config.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { runNotificaitonsUseCases } from './notification';
import { runChatUseCases, runNFTChatUseCases } from './chat';
import { runVideoUseCases } from './video';
import { runSpacesUseCases } from './spaces';
import { runPushAPICases } from './pushAPI';

import { config } from './config';
import { ENV } from './types';
Expand All @@ -14,6 +15,7 @@ const start = async (): Promise<void> => {
console.log(`${returnHeadingLog()}`);
console.log(`${returnENVLog()}`);

await runPushAPICases();
await runNotificaitonsUseCases();
await runChatUseCases();
await runNFTChatUseCases();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ enum ENV {
const { env, showAPIResponse } = config;

// If you own a channel, you can use your channel address as well
const channelPrivateKey: string = process.env.WALLET_PRIVATE_KEY!;
const channelPrivateKey = process.env.WALLET_PRIVATE_KEY;

/***************** SAMPLE SIGNER GENERATION *********************/
/**
* USING VIEM
*/
const signerChannel = createWalletClient({
account: privateKeyToAccount(`0x${channelPrivateKey}`),
chain: goerli,
transport: http(),
});
const channelAddress = signerChannel.account.address;
const signerChannel = channelPrivateKey
? createWalletClient({
account: privateKeyToAccount(`0x${channelPrivateKey}`),
chain: goerli,
transport: http(),
})
: undefined;
const channelAddress = signerChannel
? signerChannel.account.address
: undefined;
// Random Wallet Signers
const signer = createWalletClient({
account: privateKeyToAccount(generatePrivateKey()),
Expand All @@ -55,6 +59,18 @@ const randomWallet1 = privateKeyToAccount(generatePrivateKey()).address;
// const randomWallet1 = ethers.Wallet.createRandom().address;
/************************************************************* */

const skipExample = () => {
const requiredEnvVars = ['WALLET_PRIVATE_KEY'];

for (const envVar of requiredEnvVars) {
if (!process.env[envVar]) {
return true; // Skip the example if any of the required env vars is missing
}
}

return false; // All required env vars are present, don't skip the example
};

// Push Notification - Run Notifications Use cases
export const runNotificaitonsUseCases = async (): Promise<void> => {
console.log(`
Expand All @@ -73,40 +89,42 @@ export const runNotificaitonsUseCases = async (): Promise<void> => {
console.log('PushAPI.user.getSubscriptions');
await PushAPI_user_getSubscriptions();

console.log('PushAPI.channels.getChannel()');
await PushAPI_channels_getChannel();
if (!skipExample()) {
console.log('PushAPI.channels.getChannel()');
await PushAPI_channels_getChannel();

console.log('PushAPI.channels.search()');
await PushAPI_channels_search();
console.log('PushAPI.channels.search()');
await PushAPI_channels_search();

console.log('PushAPI.channels.subscribe()');
await PushAPI_channels_subscribe();
console.log('PushAPI.channels.subscribe()');
await PushAPI_channels_subscribe();

console.log('PushAPI.channels.unsubscribe()');
await PushAPI_channels_unsubscribe();
console.log('PushAPI.channels.unsubscribe()');
await PushAPI_channels_unsubscribe();

// IMPORTANT: VARIOUS OTHER NOTIFICATIONS FORMAT SUPPORTED
// EXAMPLES HERE: https://github.com/ethereum-push-notification-service/push-sdk/blob/main/packages/restapi/README.md
console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, Single Recipient]'
);
await PushAPI_payloads_sendNotification__direct_payload_single_recipient();
// IMPORTANT: VARIOUS OTHER NOTIFICATIONS FORMAT SUPPORTED
// EXAMPLES HERE: https://github.com/ethereum-push-notification-service/push-sdk/blob/main/packages/restapi/README.md
console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, Single Recipient]'
);
await PushAPI_payloads_sendNotification__direct_payload_single_recipient();

console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, Batch of Recipients (Subset)]'
);
await PushAPI_payloads_sendNotification__direct_payload_group_of_recipient_subset();
console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, Batch of Recipients (Subset)]'
);
await PushAPI_payloads_sendNotification__direct_payload_group_of_recipient_subset();

console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, All Recipients (Broadcast)]'
);
await PushAPI_payloads_sendNotification__direct_payload_all_recipients_brodcast();
console.log(
'PushAPI.payloads.sendNotification() [Direct Payload, All Recipients (Broadcast)]'
);
await PushAPI_payloads_sendNotification__direct_payload_all_recipients_brodcast();

console.log('PushAPI.channels._getSubscribers()');
await PushAPI_channels_getSubscribers();
console.log('PushAPI.channels._getSubscribers()');
await PushAPI_channels_getSubscribers();

console.log('Push Notification - PushSDKSocket()');
await PushSDKSocket();
console.log('Push Notification - PushSDKSocket()');
await PushSDKSocket();
}
};

// Push Notification - PushAPI.user.getFeeds
Expand Down Expand Up @@ -152,7 +170,7 @@ async function PushAPI_user_getSubscriptions(silent = !showAPIResponse) {
// Push Notification - PushAPI.channels.getChannel
async function PushAPI_channels_getChannel(silent = !showAPIResponse) {
const channelData = await PushAPI.channels.getChannel({
channel: channelAddress,
channel: channelAddress as string,
env: env as ENV,
});

Expand Down
17 changes: 17 additions & 0 deletions packages/examples/sdk-backend-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "sdk-backend-node",
"version": "1.0.0",
"description": "Welcome to the SDK Backend Node Example project, a hands-on guide demonstrating how to leverage the power of Push Protocol in a backend environment using Node.js. This resource is an invaluable companion for developers keen to integrate Push Protocol into their backend services. Dive into the code to gain a comprehensive understanding of how to deploy various features of the Push Protocol in a Node.js backend.",
"main": "index.js",
"scripts": {
"start": "ts-node main.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@pushprotocol/restapi": "^1.4.17",
"@pushprotocol/socket": "^0.5.2"
}
}
52 changes: 0 additions & 52 deletions packages/examples/sdk-backend-node/project.json

This file was deleted.

Loading

0 comments on commit 699706b

Please sign in to comment.