npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

we.sdk

v0.2.1

Published

providing node js interface for controlling, fetching, and modifying your account and quota on the We Telecom Egypt website I am shooting to make a complete "We SDK" for node js

Downloads

56

Readme

We Api

we.sdk is an open source package for JavaScript that acts as an Api or an SDK for We Telecom Egypt (We TE) website can only run in Egypt and with Node.js i am aiming to make this package as robust as possible and to cover all the features that the website provides please feel free to contribute to this project and make it better

DECLAIMER

⚠️⚠️⚠️⚠️⚠️⚠️⚠️ THIS PACKAGE IS NOT ASSOCIATED WITH WE TELECOM EGYPT IN ANY WAY, SHAPE OR FORM WHATSO EVER IT JUST BASED ON THE PUBLIC API THAT "WE TE" PROVIDES ON THERE WEBSITE

هذا المشروع ليس له اي علاقة نهائيا بشركة we المشروع ببساطة مبني علي الapi المتاح من خلال موقع we فقط وليس لwe اي علاقة بهاذا المشروع ⚠️⚠️⚠️⚠️⚠️⚠️⚠️

Installation

npm install we.sdk
yarn add we.sdk

Usage

there are two ways to use this package

  1. only using the plain api
  2. using the cached api (recommended and optimized)

Normal API usage

const { WeApi, WeApiError } = require('we.sdk')

const main = async (number, password) => {
   try {
      const session = await WeApi.userAuthenticate(number, password)
      const balance = await WeApi.getBalance(session)
      const quota = await WeApi.getFreeUnits(session)

      console.log(JSON.stringify(session, null, 2))
      console.log(JSON.stringify(balance, null, 2))
      console.log(JSON.stringify(quota, null, 2))
   } catch (error) {
      if (error instanceof WeApiError) {
         return console.log('We Api Error:', error.message)
      }
   }
}

main(process.argv[2], process.argv[3])

Cached API usage

const { WeCachedApi, WeApiError, CacheProviderInMemory, CacheProviderInFile } = require('we.sdk')

const main = async (number, password) => {
   try {
      const weCachedApi = new WeCachedApi({
         customer: {
            number: number,
            password: password,
         },
         CacheProvider: CacheProviderInFile, // or CacheProviderInMemory
         cachePath: './cache.json', // only needed if you are using CacheProviderInFile
         ttlInMs: {
            session: 3.5 * 60 * 60 * 1000, // 3.5 hours before the session expires
            balance: 10 * 60 * 1000, // 10 minutes before the balance expires
            freeUnit: 10 * 60 * 1000, // 10 minutes before the freeUnit expires
         },
         hooks: {
            beforeRequest: (key) => {
               console.log('beforeRequest', key) // will be called before the request if not cached
            },
            afterRequest: (key) => {
               console.log('afterRequest', key) // will be called after the request if not cached
            },
         },
      })

      const session = await weCachedApi.userAuthenticate()
      const balance = await weCachedApi.getBalance() // if session is not cached it will call userAuthenticate first
      const quota = await weCachedApi.getFreeUnits() // if session is not cached it will call userAuthenticate first

      console.log(JSON.stringify(session, null, 2))
      console.log(JSON.stringify(balance, null, 2))
      console.log(JSON.stringify(quota, null, 2))
   } catch (error) {
      if (error instanceof WeApiError) {
         return console.log('We Api Error:', error.message)
      }
   }
}

Todo List

  • [x] userAuthenticate - login user with phone number and password
  • [x] getBalance - get user balance
  • [x] getBalanceInfo - get user balance info
  • [ ] checkIfCanRenew - check if user can renew his main subscription
  • [ ] renewMainSubscription - renew user main subscription
  • [x] ApiCaching version

Api

WeApi (class)

const { WeApi } = require('we.sdk')

WeApi.userAuthenticate

WeApi.userAuthenticate(number: string, password: string): Promise<Session>

const session = await WeApi.userAuthenticate(number, password)

| parameter | type | required | example | note | | --------- | ------ | -------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | number | string | yes | 0223123456 | It can be in any valid Egyptian landline number ex: +20223123456, 0020223123456,+20-2-2312-3456, 68-312-3456, 02-2312-3456any Egyptian number that can be parsed with libphonenumber-js is validyou can check the logic behind it in phoneParser.js | | password | string | yes | myPassword | Your WE TE account password (this is not being stored, sent, or modified in any sort) |

Return: Promise<Session> Errors: Possible Errors

WeApi.getBalance

WeApi.getBalance(session: Session): Promise<UserBalanceInfo>

const balance = await WeApi.getBalance(session)

| parameter | type | required | example | note | | --------- | -------------------------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | session | Session | yes | | only parts needed from the Session Object not all for more details check the input from more info check the method input here |

Return: Promise<UserBalanceInfo> Errors: Possible Errors

WeApi.getFreeUnits

WeApi.getFreeUnits(session: Session): Promise<FreeUnit[]>

const quota = await WeApi.getFreeUnits(session)

| parameter | type | required | example | note | | --------- | -------------------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | session | Session | yes | | only parts needed from the Session Object not all for more details check the input from more info check the method input here |

Return: Promise<FreeUnit[]> Errors: Possible Errors

WeCachedApi (class)

const { WeCachedApi } = require('we.sdk')

WeCachedApi.constructor

new WeCachedApi(options: object)

const WeCachedApi = new WeCachedApi({
   customer: {
      number: number,
      password: password,
   },
   CacheProvider: CacheProviderInFile, // or CacheProviderInMemory
   cachePath: './cache.json', // only needed if you are using CacheProviderInFile
   ttlInMs: {
      session: 3.5 * 60 * 60 * 1000, // 3.5 hours before the session expires
      balance: 10 * 60 * 1000, // 10 minutes before the balance expires
      freeUnit: 10 * 60 * 1000, // 10 minutes before the freeUnit expires
   },
   hooks: {
      beforeRequest: (key) => {
         console.log('beforeRequest', key) // will be called before the request if not cached
      },
      afterRequest: (key) => {
         console.log('afterRequest', key) // will be called after the request if not cached
      },
   },
})

| parameter | type | required | example | note | | ------------ | ------ | -------- | ------- | ---- | | options | object | yes | | | | customer | object | yes | | | | customer.number | string | yes | 0223123456 | It can be in any valid Egyptian landline number ex: +20223123456, 0020223123456,+20-2-2312-3456, 68-312-3456, 02-2312-3456any Egyptian number that can be parsed with libphonenumber-js is validyou can check the logic behind it in phoneParser.js | | customer.password | string | yes | myPassword | Your WE TE account password (this is not being stored, sent, or modified in any sort) | | CacheProvider | class | no, default: CacheProviderInMemory | CacheProviderInFile or CacheProviderInMemory | the class that will be used to cache the data you can create your own cache provider by extending the CacheProviderInterface and implementing the methods | | cachePath | string | no, default: './cache.json' | './cache.json' | only needed if you are using CacheProviderInFile | | ttlInMs | object | no, default: { session: 3.5 * 60 * 60 * 1000, balance: 10 * 60 * 1000, freeUnit: 10 * 60 * 1000 } | { session: 3.5 * 60 * 60 * 1000, balance: 10 * 60 * 1000, freeUnit: 10 * 60 * 1000 } | the time to live for each cached item in milliseconds | | hooks | object | no | | hooks that will be called before and after the request if not cached |

WeCachedApi.*

the same as WeApi but with caching

CacheProviderInMemory (class)

used as a cache provider for the WeCachedApi class

const { CacheProviderInMemory } = require('we.sdk')

CacheProviderInFile (class)

used as a cache provider for the WeCachedApi class requires the cachePath parameter in the WeCachedApi.constructor

const { CacheProviderInFile } = require('we.sdk')

CacheProviderInterface (interface)

used to create your own cache provider for the WeCachedApi class

const { CacheProviderInterface } = require('we.sdk')

WeApiError (class) inherits from Error

const { WeApiError } = require('we.sdk')
  • has the same properties as the Error class
  • has an additional property code which is the error code
  • has name property set to WeApiError

Error Codes

Accessed by WeApiError instances error.code

const { WeApiError } = require('we.sdk')

try {
   // some code
} catch (error) {
   if (error instanceof WeApiError) {
      console.log('We Api Error:', error.message)
      console.log('We Api Error Code:', error.code)
   }
   //or

   if (error.name === 'WeApiError') {
      console.log('We Api Error:', error.message)
      console.log('We Api Error Code:', error.code)
   }
}
  • WE_INVALID_CREDENTIALS
  • WE_INVALID_SESSION
  • WE_INVALID_PHONE_NUMBER
  • WE_INVALID_RESPONSE
  • WE_RATE_LIMITED
  • WE_SERVER_ERROR
  • WE_INVALID_CACHE_PROVIDER

types

IndividualInfo

Customer

Account

Subscriber

UserResponse (session)

BalanceDetail

BalanceInfo

CreditInfo

UserBalanceInfo

FreeUnitBeanDetail

FreeUnit

Contributing

this project is open for contributions, feel free to open an issue or a pull request you can complete the todo list or add new features, optimize the code, or fix bugs make sure you write the code as clean as possible and add comments

License

MIT