@docbox-nz/hapi-gateway 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.github/workflows/build.yml +30 -0
  2. package/.github/workflows/release.yml +37 -0
  3. package/.oxfmtrc.json +8 -0
  4. package/.oxlintrc.json +11 -0
  5. package/.zed/settings.json +10 -0
  6. package/README.md +32 -38
  7. package/cspell.json +1 -4
  8. package/dist/index.node.cjs +15031 -21882
  9. package/dist/index.node.cjs.map +1 -1
  10. package/dist/index.node.esm.js +15024 -21880
  11. package/dist/index.node.esm.js.map +1 -1
  12. package/package.json +44 -55
  13. package/rolldown.config.js +19 -0
  14. package/src/index.ts +257 -257
  15. package/tsconfig.json +15 -15
  16. package/.eslintignore +0 -6
  17. package/.eslintrc +0 -131
  18. package/.prettierignore +0 -11
  19. package/.prettierrc +0 -6
  20. package/dist/api/adminService.d.ts +0 -16
  21. package/dist/api/boxService.d.ts +0 -43
  22. package/dist/api/client.d.ts +0 -45
  23. package/dist/api/docboxFile.d.ts +0 -15
  24. package/dist/api/fileService.d.ts +0 -251
  25. package/dist/api/folderService.d.ts +0 -45
  26. package/dist/api/linkService.d.ts +0 -115
  27. package/dist/api/taskService.d.ts +0 -23
  28. package/dist/api/utils.d.ts +0 -1
  29. package/dist/error.d.ts +0 -11
  30. package/dist/index.browser.cjs +0 -988
  31. package/dist/index.browser.cjs.map +0 -1
  32. package/dist/index.browser.esm.js +0 -984
  33. package/dist/index.browser.esm.js.map +0 -1
  34. package/dist/index.browser.js +0 -4390
  35. package/dist/index.browser.js.map +0 -1
  36. package/dist/index.d.ts +0 -4
  37. package/dist/index.node.js +0 -20809
  38. package/dist/index.node.js.map +0 -1
  39. package/dist/options.d.ts +0 -85
  40. package/dist/types/box.d.ts +0 -59
  41. package/dist/types/file.d.ts +0 -371
  42. package/dist/types/folder.d.ts +0 -153
  43. package/dist/types/index.d.ts +0 -22
  44. package/dist/types/link.d.ts +0 -136
  45. package/dist/types/search.d.ts +0 -177
  46. package/dist/types/shared.d.ts +0 -94
  47. package/dist/types/user.d.ts +0 -20
  48. package/rollup.config.js +0 -36
@@ -0,0 +1,30 @@
1
+ name: Build
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout code
14
+ uses: actions/checkout@v4
15
+
16
+ - name: Setup Node.js
17
+ uses: actions/setup-node@v4
18
+ with:
19
+ node-version: '24'
20
+
21
+ - name: Setup pnpm
22
+ uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5
23
+ with:
24
+ cache: true
25
+
26
+ - name: Install dependencies
27
+ run: pnpm install --frozen-lockfile
28
+
29
+ - name: Build
30
+ run: pnpm build
@@ -0,0 +1,37 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '*.*.*'
7
+
8
+ permissions:
9
+ contents: read
10
+ id-token: write
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ environment: publish_npm
16
+ steps:
17
+ - name: Checkout code
18
+ uses: actions/checkout@v4
19
+
20
+ - name: Setup Node.js
21
+ uses: actions/setup-node@v4
22
+ with:
23
+ node-version: '24'
24
+ registry-url: 'https://registry.npmjs.org'
25
+ package-manager-cache: false
26
+
27
+ - name: Setup pnpm
28
+ uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5
29
+
30
+ - name: Install dependencies
31
+ run: pnpm install --frozen-lockfile
32
+
33
+ - name: Build
34
+ run: pnpm build
35
+
36
+ - name: Publish
37
+ run: pnpm publish --no-git-checks
package/.oxfmtrc.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "./node_modules/oxfmt/configuration_schema.json",
3
+ "printWidth": 100,
4
+ "singleQuote": true,
5
+ "trailingComma": "es5",
6
+ "tabWidth": 2,
7
+ "ignorePatterns": []
8
+ }
package/.oxlintrc.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "./node_modules/oxlint/configuration_schema.json",
3
+ "plugins": ["typescript", "unicorn", "oxc"],
4
+ "categories": {
5
+ "correctness": "error"
6
+ },
7
+ "rules": {},
8
+ "env": {
9
+ "builtin": true
10
+ }
11
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "prettier": {
3
+ "allowed": false
4
+ },
5
+ "formatter": {
6
+ "language_server": {
7
+ "name": "oxfmt"
8
+ }
9
+ }
10
+ }
package/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # 📦 @docbox-nz/hapi-gateway
2
2
 
3
- Docbox Gateway implementation for hapi
3
+ Docbox Gateway implementation for hapi
4
4
 
5
5
  Provides routes for forwarding requests to docbox and methods for enforcing access control over said routes
6
6
 
7
7
  ## Requirements
8
+
8
9
  - Hapi.js v20.1.0 or newer
9
10
  - Node.js 20+
10
11
 
@@ -18,13 +19,12 @@ npm i @docbox-nz/hapi-gateway
18
19
 
19
20
  You will also need to ensure that you have `@hapi/hapi` installed this plugin supports versions `^20.1.0 || ^21.0.0`
20
21
 
21
-
22
22
  ## Plugin setup
23
23
 
24
24
  For a simple installation where not much additional logic is required, you can add the following to your server setup
25
25
 
26
26
  ```js
27
- import { DocboxGateway } from "@docbox-nz/hapi-gateway";
27
+ import { DocboxGateway } from '@docbox-nz/hapi-gateway';
28
28
 
29
29
  server.register({
30
30
  plugin: DocboxGateway,
@@ -32,25 +32,25 @@ server.register({
32
32
  // Prefix all routes with /data
33
33
  basePath: '/data',
34
34
  // Base request options for docbox routes
35
- baseRouteOptions: { },
35
+ baseRouteOptions: {},
36
36
  // URL for the docbox API
37
- docboxBaseURL: "http://docbox-server",
37
+ docboxBaseURL: 'http://docbox-server',
38
38
 
39
39
  // Get the tenant for a request
40
40
  getRequestTenant(request) {
41
41
  // ..derive your target tenant
42
42
  // this can be hard-coded for single tenant setups
43
- return { id: '81284060-9542-4d66-9731-49ca3eb93bf9', env: "Development"}
43
+ return { id: '81284060-9542-4d66-9731-49ca3eb93bf9', env: 'Development' };
44
44
  },
45
45
 
46
46
  // Get the user for a request
47
47
  getRequestUser(request) {
48
48
  // ..derive your request user
49
49
  return {
50
- id: "dd5ba8b5-7da2-4e8b-b255-9641faece80e",
51
- name: "Example User",
52
- imageId: "https://example.com/example.png"
53
- }
50
+ id: 'dd5ba8b5-7da2-4e8b-b255-9641faece80e',
51
+ name: 'Example User',
52
+ imageId: 'https://example.com/example.png',
53
+ };
54
54
  },
55
55
 
56
56
  // Check request read access
@@ -64,7 +64,7 @@ server.register({
64
64
  // ..assert request is allowed to access scope
65
65
  return true;
66
66
  },
67
- }
67
+ },
68
68
  });
69
69
  ```
70
70
 
@@ -73,31 +73,31 @@ server.register({
73
73
  If you have a more complex routing setup for your hapi app, you can use the `createDocboxRoutes` function to create a docbox setup and obtain a list of routes that you can manually add using `server.route`
74
74
 
75
75
  ```js
76
- import { createDocboxRoutes } from "@docbox-nz/hapi-gateway";
76
+ import { createDocboxRoutes } from '@docbox-nz/hapi-gateway';
77
77
 
78
78
  const routes = createDocboxRoutes({
79
79
  // Prefix all routes with /data
80
80
  basePath: '/data',
81
81
  // Base request options for docbox routes
82
- baseRouteOptions: { },
82
+ baseRouteOptions: {},
83
83
  // URL for the docbox API
84
- docboxBaseURL: "http://docbox-server",
84
+ docboxBaseURL: 'http://docbox-server',
85
85
 
86
86
  // Get the tenant for a request
87
87
  getRequestTenant(request) {
88
88
  // ..derive your target tenant
89
89
  // this can be hard-coded for single tenant setups
90
- return { id: '81284060-9542-4d66-9731-49ca3eb93bf9', env: "Development"}
90
+ return { id: '81284060-9542-4d66-9731-49ca3eb93bf9', env: 'Development' };
91
91
  },
92
92
 
93
93
  // Get the user for a request
94
94
  getRequestUser(request) {
95
95
  // ..derive your request user
96
96
  return {
97
- id: "dd5ba8b5-7da2-4e8b-b255-9641faece80e",
98
- name: "Example User",
99
- imageId: "https://example.com/example.png"
100
- }
97
+ id: 'dd5ba8b5-7da2-4e8b-b255-9641faece80e',
98
+ name: 'Example User',
99
+ imageId: 'https://example.com/example.png',
100
+ };
101
101
  },
102
102
 
103
103
  // Check request read access
@@ -116,10 +116,9 @@ const routes = createDocboxRoutes({
116
116
  module.exports = routes;
117
117
  ```
118
118
 
119
+ ## Example access control
119
120
 
120
- ## Example access control
121
-
122
- Access control is enforced on a scope level, you should check the `scope` (Document box scope) and decide whether the request should be allowed based
121
+ Access control is enforced on a scope level, you should check the `scope` (Document box scope) and decide whether the request should be allowed based
123
122
  on some information extracted from the request (or some other available context)
124
123
 
125
124
  > [!NOTE]
@@ -129,24 +128,19 @@ on some information extracted from the request (or some other available context)
129
128
  > `isAllowedWrite` also enforces the access control for creating new document boxes. Requests to `POST /box` are document box creation requests.
130
129
 
131
130
  ```js
132
-
133
131
  function isAllowedWrite(request, scope, path) {
132
+ // Get authenticated user scopes
133
+ const userScopes = request.auth.credentials.scope;
134
134
 
135
- // Get authenticated user scopes
136
- const userScopes = request.auth.credentials.scope
137
-
138
- // User is trying to access the "admin-area" scope
139
- if (scope === "admin-area") {
140
-
141
- // Ensure the user has the required admin scope
142
- if (userScopes.includes('admin')) {
143
- return true;
144
- }
145
-
135
+ // User is trying to access the "admin-area" scope
136
+ if (scope === 'admin-area') {
137
+ // Ensure the user has the required admin scope
138
+ if (userScopes.includes('admin')) {
139
+ return true;
146
140
  }
141
+ }
147
142
 
148
- // Deny by default
149
- return false;
150
- }
151
-
143
+ // Deny by default
144
+ return false;
145
+ }
152
146
  ```
package/cspell.json CHANGED
@@ -1,6 +1,3 @@
1
1
  {
2
- "words": [
3
- "Docbox",
4
- "Jacobtread"
5
- ]
2
+ "words": ["Docbox", "Jacobtread"]
6
3
  }