Skip to content

Commit

Permalink
Merge pull request #408 from nextcloud/feature/bundle-improvements
Browse files Browse the repository at this point in the history
Bundle improvements
  • Loading branch information
vinicius73 authored Aug 11, 2022
2 parents ec76d5d + e5f8103 commit d664645
Show file tree
Hide file tree
Showing 13 changed files with 5,253 additions and 5,463 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Node

on:
pull_request:
push:
branches:
- 'master'

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [16, 18]
name: Test Node v${{ matrix.node }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- name: install dependencies
run: npm ci
- name: build package
run: npm run build
- name: run tests
run: npm run test

summary:
runs-on: ubuntu-latest
needs: test
if: always()
name: test-summary
steps:
- name: Summary status
run: if ${{ needs.test.result != 'success' && needs.test.result != 'skipped' }}; then exit 1; fi
5 changes: 2 additions & 3 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
uses: skjnldsv/read-package-engines-version-actions@v1.2
id: versions
with:
fallbackNode: '^12'
fallbackNpm: '^6'
fallbackNode: '^16'
fallbackNpm: '^8'

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@v3
Expand All @@ -55,4 +55,3 @@ jobs:
git status
git --no-pager diff
exit 1 # make it red to grab attention
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file.

## 2.0.0 - Draft
### Added
- Rollup as bundler
- ESM bundle

### Changed
- Remove core-js
- Remove babel
- Remove unnecessary dev dependencies
- README.md

## 1.3.0 - 2020-06-04
### Added
- isAdmin prop to the user object
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# @nextcloud/auth

Nextcloud helpers related to authentication and the current user

## Install

```sh
yarn add @nextcloud/auth
```

```sh
npm install @nextcloud/auth --save
```

## Usage

```ts
import {
getRequestToken,
getCurrentUser,
onRequestTokenUpdate,
} from '@nextcloud/auth'

const user = getCurrentUser()

if (user.isAdmin) {
// do something
}
```

For more imformation check [nextcloud.github.io/nextcloud-auth](https://nextcloud.github.io/nextcloud-auth/index.html)
15 changes: 0 additions & 15 deletions babel.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {
getRequestToken,
onRequestTokenUpdate
} from './requesttoken'
export type { CsrfTokenObserver } from './requesttoken'
export type { NextcloudUser } from './user'

export { getRequestToken, onRequestTokenUpdate } from './requesttoken'
export { getCurrentUser } from './user'
4 changes: 2 additions & 2 deletions lib/requesttoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { subscribe } from '@nextcloud/event-bus'
const tokenElement = document.getElementsByTagName('head')[0]
let token = tokenElement ? tokenElement.getAttribute('data-requesttoken') : null

interface CsrfTokenObserver {
export interface CsrfTokenObserver {
(token: string): void;
}

const observers: Array<CsrfTokenObserver> = []
const observers: CsrfTokenObserver[] = []

export function getRequestToken(): string | null {
return token
Expand Down
26 changes: 19 additions & 7 deletions lib/user.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
/// <reference types="@nextcloud/typings" />

declare var OC: Nextcloud.v16.OC | Nextcloud.v17.OC | Nextcloud.v18.OC | Nextcloud.v19.OC | Nextcloud.v20.OC;
declare var OC: Nextcloud.v16.OC
| Nextcloud.v17.OC
| Nextcloud.v18.OC
| Nextcloud.v19.OC
| Nextcloud.v20.OC
| Nextcloud.v21.OC
| Nextcloud.v22.OC
| Nextcloud.v20.OC
| Nextcloud.v24.OC;

const uidElement = document
.getElementsByTagName('head')[0]
const uid = uidElement ? uidElement.getAttribute('data-user') : null
const getAttribute = (el: HTMLHeadElement | undefined, attribute: string): string | null => {
if (el) {
return el.getAttribute(attribute)
}

return null
}

const displayNameElement = document
.getElementsByTagName('head')[0]
const displayName = displayNameElement ? displayNameElement.getAttribute('data-user-displayname') : null
const head = document.getElementsByTagName('head')[0]
const uid = getAttribute(head, 'data-user')
const displayName = getAttribute(head, 'data-user-displayname')

const isAdmin = (typeof OC === 'undefined')
? false
Expand Down
Loading

0 comments on commit d664645

Please sign in to comment.