Skip to content

Commit

Permalink
feat: expose creator, coordinator, and member role IDs (#704)
Browse files Browse the repository at this point in the history
You can now import `CREATOR_ROLE_ID`, `COORDINATOR_ROLE_ID`, and
`MEMBER_ROLE_ID`.

```javascript
import { roles } from '@mapeo/core'

myProject.$member.invite(deviceId, { roleId: roles.MEMBER_ROLE_ID })
```

CoMapeo Mobile [currently hard-codes these values][0].

Note that "weirder" IDs, like `LEFT_ROLE_ID`, are deliberately *not
exported right now* because they're easy to add later if needed.

Closes [#532].

[#532]: #532
[0]: https://github.com/digidem/comapeo-mobile/blob/2cfa789360a2faa066a85fde8aad73d5e80a5dfd/src/frontend/sharedTypes/index.ts#L31-L37
  • Loading branch information
EvanHahn authored Jun 24, 2024
1 parent f0997b6 commit bd492c4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import {
CREATOR_ROLE_ID,
COORDINATOR_ROLE_ID,
MEMBER_ROLE_ID,
} from './roles.js'
export { plugin as MapeoStaticMapsFastifyPlugin } from './fastify-plugins/maps/static-maps.js'
export { plugin as MapeoOfflineFallbackMapFastifyPlugin } from './fastify-plugins/maps/offline-fallback-map.js'
export { plugin as MapeoMapsFastifyPlugin } from './fastify-plugins/maps/index.js'
export { FastifyController } from './fastify-controller.js'
export { MapeoManager } from './mapeo-manager.js'

export const roles = /** @type {const} */ ({
CREATOR_ROLE_ID,
COORDINATOR_ROLE_ID,
MEMBER_ROLE_ID,
})
4 changes: 3 additions & 1 deletion test-e2e/manager-invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import assert from 'node:assert/strict'
import { InviteResponse_Decision } from '../src/generated/rpc.js'
import { once } from 'node:events'
import { connectPeers, createManagers, waitForPeers } from './utils.js'
import { COORDINATOR_ROLE_ID, MEMBER_ROLE_ID } from '../src/roles.js'
import { roles } from '../src/index.js'

const { COORDINATOR_ROLE_ID, MEMBER_ROLE_ID } = roles

/** @typedef {import('../src/generated/rpc.js').Invite} Invite */

Expand Down
5 changes: 2 additions & 3 deletions test-e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import { createRequire } from 'node:module'
import { fileURLToPath } from 'node:url'
import * as v8 from 'node:v8'

import { MapeoManager } from '../src/index.js'
import { MapeoManager, roles } from '../src/index.js'
import { kManagerReplicate, kRPC } from '../src/mapeo-manager.js'
import { once } from 'node:events'
import { generate } from '@mapeo/mock-data'
import { valueOf } from '../src/utils.js'
import { randomInt } from 'node:crypto'
import { temporaryFile, temporaryDirectory } from 'tempy'
import fsPromises from 'node:fs/promises'
import { MEMBER_ROLE_ID } from '../src/roles.js'
import { kSyncState } from '../src/sync/sync-api.js'
import { readConfig } from '../src/config-import.js'

Expand Down Expand Up @@ -91,7 +90,7 @@ export async function invite({
invitor,
projectId,
invitees,
roleId = MEMBER_ROLE_ID,
roleId = roles.MEMBER_ROLE_ID,
roleName,
reject = false,
}) {
Expand Down

0 comments on commit bd492c4

Please sign in to comment.