open-index/open-npm huggingface dataset:
npm package: @share911/meteor-error
Description: Port of the Meteor.Error class from Meteor.
Latest version: 1.0.0

# meteor-error

Port of the Meteor.Error class from Meteor.

## Usage

```js
import * as Meteor from '@share911/meteor-error'

throw new Meteor.Error(500, 'Internal server error')
```

or

```js
import { Error as MeteorError } from '@share911/meteor-error'

throw new MeteorError(500, 'Internal server error')
```

[Full documentation](https://docs.meteor.com/api/methods.html#Meteor-Error)
npm package: @share911/meteor-sha
Description: Port of the Meteor sha package.
Latest version: 1.0.0

# meteor-sha

Port of the Meteor sha package.

An implementation of the [SHA256](https://en.wikipedia.org/wiki/SHA-2) secure hash function, available in all environments.

## Usage

```js
import { SHA256 } from '@share911/meteor-sha'

SHA256('meteor') // Returns "647d177cca8601046a3cb39e12f55bec5790bfcbc42199dd5fcf063200fac1d0"
```
npm package: @share911/roles
Description: Scope-aware roles and permissions helpers for applications backed by MongoDB. Keep your authorization model simple: assign permissions within scopes (e.g., per tenant/project) and use a special global scope for permissions that apply everywhere.
Latest version: 1.0.5

# @share911/roles
Scope-aware roles and permissions helpers for applications backed by MongoDB. Keep your authorization model simple: assign permissions within scopes (e.g., per tenant/project) and use a special global scope for permissions that apply everywhere.

## Installation

Using npm:
```sh
npm install @share911/roles
```

Using yarn: 
```sh
yarn add @share911/roles
```

Using pnpm:
```sh
pnpm add @share911/roles
```


## Concepts
- A user has an array of role entries. Each entry contains:
  - scope: string identifier (e.g., project:alpha, tenant/123, organization1)
  - permissions: string[] (e.g., ['admin', 'editor'])
- A special constant GLOBAL_SCOPE allows you to grant permissions that apply across all scopes.

## Quick start
- Check permissions at runtime:
```typescript
import { userIsInRole, GLOBAL_SCOPE, type RolesUser } from '@share911/roles/dist'

// get user object from database
const user: RolesUser = await getUserById('user-123')

// Structure of `user` object:
// {
//   _id: 'user-123',
//   roles: [
//     { scope: 'project:alpha', permissions: ['viewer'] },
//     { scope: GLOBAL_SCOPE, permissions: ['admin'] },
//   ],
// }

// check permissions
userIsInRole(user, 'admin') // true via global
userIsInRole(user, 'viewer', 'project:alpha') // true via specific scope
userIsInRole(user, ['editor', 'admin'], 'project:alpha') // true via global
userIsInRole(user, 'editor', 'project:beta') // false
```

- Add permissions to users for a scope:
```typescript
import { addUsersToRoles, GLOBAL_SCOPE, type RolesUser, type UpdateType } from '@share911/roles/dist'
import { MongoClient } from 'mongodb'

type User = RoleUser & {
  name: string
}

async function grantGlobalAdmin(userIds: string[]) {
 const users = client.db('<DB_NAME>').collection<User>('users')

  const updateMany: UpdateType<User> = (filter, update, options) =>
    users.updateMany(filter, update, options).bind(users)

  await addUsersToRoles(updateMany, userIds, ['admin'], GLOBAL_SCOPE);

  await client.close()
}
```

## Test
You need a MongoDB server running locally.
```sh
npm test
```