@flipdish/authorization 0.1.9 → 0.2.0-rc.1760627866

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.
@@ -1,5 +1,6 @@
1
1
  .gitignore
2
2
  .npmignore
3
+ .openapi-generator-ignore
3
4
  README.md
4
5
  api.ts
5
6
  base.ts
package/README.md CHANGED
@@ -7,136 +7,174 @@ Internally the package utilizes the [axios](https://github.com/axios/axios) as i
7
7
  ### Example code
8
8
 
9
9
  ```typescript
10
- import { AuthorizationApi, Configuration, PermissionsApi, Permissions, UserPermissionsApi } from '@flipdish/authorization';
11
- import { describe, expect, test, it } from '@jest/globals';
12
- import axios from 'axios';
10
+ import {
11
+ AuthorizationApi,
12
+ Configuration,
13
+ type ErrorResponse,
14
+ Permissions,
15
+ PermissionsApi,
16
+ UserPermissionsApi,
17
+ } from "@flipdish/authorization";
18
+ import { describe, expect, it, test } from "@jest/globals";
19
+ import axios, { isAxiosError } from "axios";
13
20
 
14
21
  const basePath = "https://api.flipdish.co/auth/";
15
22
  const bearerConfiguration = new Configuration({
16
- basePath,
17
- // to get the API key, you should follow these docs:
18
- // https://developers.flipdish.com/docs/getting-started
19
- accessToken: process.env.FLIPDISH_BEARER_TOKEN_PROD,
20
- // if using in a browser set useDefaultUserAgent
21
- // to true to prevent errors
22
- // useDefaultUserAgent: true
23
+ basePath,
24
+ // to get the API key, you should follow these docs:
25
+ // https://developers.flipdish.com/docs/getting-started
26
+ accessToken: process.env.FLIPDISH_BEARER_TOKEN_PROD,
27
+ // if using in a browser set useDefaultUserAgent
28
+ // to true to prevent errors
29
+ // useDefaultUserAgent: true
23
30
  });
24
31
 
25
32
  const authorization = new AuthorizationApi(bearerConfiguration);
26
33
  const permissions = new PermissionsApi(bearerConfiguration);
27
34
 
28
35
  // mimic brower config where cookies will be sent automatically
29
- // you shouldn't need to pass an axios instance as the cookies will be
36
+ // you shouldn't need to pass an axios instance as the cookies will be
30
37
  // sent automatically by the browser
31
38
  const userPermissions = new UserPermissionsApi(
32
- new Configuration({ basePath }), undefined,
33
- axios.create({ headers: { 'Cookie': `FD-Authorization=${process.env.FD_AUTH_COOKIE_PROD_JM_CLIENT};` } }),
39
+ new Configuration({ basePath }),
40
+ undefined,
41
+ axios.create({
42
+ headers: {
43
+ Cookie: `FD-Authorization=${process.env.FD_AUTH_COOKIE_PROD_JM_CLIENT};`,
44
+ },
45
+ }),
34
46
  );
35
47
 
36
- describe('Authorization Tests', () => {
37
- describe('Authorization', () => {
38
-
39
- test('List Permissions', async () => {
40
- const permissionsResponse = await permissions.listPermissions();
41
- expect(permissionsResponse.status).toBe(200);
42
- expect(permissionsResponse.data.permissions).toBeDefined();
43
- expect(permissionsResponse.data.permissions.length).toBeGreaterThan(0);
44
- expect(permissionsResponse.data.permissions).toContain(Permissions.ViewApp);
45
- expect(permissionsResponse.data.permissions).toContain(Permissions.CreateApp);
46
- expect(permissionsResponse.data.permissions).toContain(Permissions.UpdateApp);
47
- expect(permissionsResponse.data.permissions).toContain(Permissions.ViewAppName);
48
- expect(permissionsResponse.data.permissions).toContain(Permissions.EditAppAssets);
49
- });
50
-
51
- describe('List User Permission Sets', () => {
52
- it('should list user permission sets', async () => {
53
- const userPermissionSetsResponse = await userPermissions.listOwnPermissions("org42068");
54
- expect(userPermissionSetsResponse.status).toBe(200);
55
- expect(userPermissionSetsResponse.data.resources).toBeDefined();
56
- expect(userPermissionSetsResponse.data.resources).toHaveProperty("org42068");
57
- expect(userPermissionSetsResponse.data.resources["org42068"].permissions.length).toBeGreaterThan(0);
58
- });
59
- });
60
-
61
- describe('Authenticate and Authorize', () => {
62
- it('should authenticate and authorize with a valid FD-Authorization cookie', async () => {
63
- const authorizationResponse = await authorization.authenticateAndAuthorize({
64
- headers: {
65
- 'Cookie': `FD-Authorization=${process.env.FD_AUTH_COOKIE_PROD};`,
66
- },
67
- action: Permissions.AnyAuditLogs,
68
- resource: {
69
- id: "org12345",
70
- type: "Org",
71
- }
72
- });
73
-
74
- expect(authorizationResponse.status).toBe(200);
75
- expect(authorizationResponse.data.authentication.authenticated).toBe(true);
76
- expect(authorizationResponse.data.authentication.principal?.type).toBe("User");
77
- expect(authorizationResponse.data.authentication.principal?.id).toBe("8147747");
78
- });
79
-
80
- it('should not authenticate and authorize with an invalid FD-Authorization cookie', async () => {
81
- try {
82
- await authorization.authenticateAndAuthorize({
83
- headers: {
84
- 'Cookie': `FD-Authorization=not-a-valid-cookie;`,
85
- },
86
- action: Permissions.AnyAuditLogs,
87
- resource: {
88
- id: "org12345",
89
- type: "Org",
90
- },
91
- });
92
- } catch (error: any) {
93
- expect(error.response.status).toBe(401);
94
- expect(error.response.data.message).toBe("Unauthenticated");
95
- }
96
- });
97
-
98
- it('should authenticate and authorize with a valid Bearer token', async () => {
99
- const authorizationResponse = await authorization.authenticateAndAuthorize({
100
- headers: {
101
- 'Authorization': `Bearer ${process.env.FLIPDISH_BEARER_TOKEN_PROD}`,
102
- },
103
- action: Permissions.AnyAuditLogs,
104
- resource: {
105
- id: "org12345",
106
- type: "Org",
107
- }
108
- });
109
-
110
- expect(authorizationResponse.status).toBe(200);
111
- expect(authorizationResponse.data.authentication.authenticated).toBe(true);
112
- expect(authorizationResponse.data.authentication.principal?.type).toBe("User");
113
- expect(authorizationResponse.data.authentication.principal?.id).toBe("8147747");
114
- });
115
- });
116
-
117
-
118
- test('Authorize', async () => {
119
- let testPrincipal: any = {
120
- id: "12345",
121
- type: "User",
122
- };
123
-
124
- let testResource: any = {
125
- id: "org12345",
126
- type: "Org",
127
- };
128
-
129
- const authorizationResponse = await authorization.authorize({
130
- principal: testPrincipal,
131
- action: Permissions.AnyAuditLogs,
132
- resource: testResource
133
- });
134
- expect(authorizationResponse.status).toBe(200);
135
- expect(authorizationResponse.data.allowed).toBe(false);
136
- expect(authorizationResponse.data.decision).toBe("DENY");
137
- });
48
+ describe("Authorization Tests", () => {
49
+ describe("Authorization", () => {
50
+ test("List Permissions", async () => {
51
+ const permissionsResponse = await permissions.listPermissions();
52
+ expect(permissionsResponse.status).toBe(200);
53
+ expect(permissionsResponse.data.permissions).toBeDefined();
54
+ expect(permissionsResponse.data.permissions.length).toBeGreaterThan(0);
55
+ expect(permissionsResponse.data.permissions).toContain(
56
+ Permissions.ViewApp,
57
+ );
58
+ expect(permissionsResponse.data.permissions).toContain(
59
+ Permissions.CreateApp,
60
+ );
61
+ expect(permissionsResponse.data.permissions).toContain(
62
+ Permissions.UpdateApp,
63
+ );
64
+ expect(permissionsResponse.data.permissions).toContain(
65
+ Permissions.ViewAppName,
66
+ );
67
+ expect(permissionsResponse.data.permissions).toContain(
68
+ Permissions.EditAppAssets,
69
+ );
138
70
  });
71
+
72
+ describe("List User Permission Sets", () => {
73
+ it("should list user permission sets", async () => {
74
+ const userPermissionSetsResponse =
75
+ await userPermissions.listOwnPermissions("org42068");
76
+ expect(userPermissionSetsResponse.status).toBe(200);
77
+ expect(userPermissionSetsResponse.data.resources).toBeDefined();
78
+ expect(userPermissionSetsResponse.data.resources).toHaveProperty(
79
+ "org42068",
80
+ );
81
+ expect(
82
+ userPermissionSetsResponse.data.resources.org42068.permissions.length,
83
+ ).toBeGreaterThan(0);
84
+ });
85
+ });
86
+
87
+ describe("Authenticate and Authorize", () => {
88
+ it("should authenticate and authorize with a valid FD-Authorization cookie", async () => {
89
+ const authorizationResponse =
90
+ await authorization.authenticateAndAuthorize({
91
+ headers: {
92
+ Cookie: `FD-Authorization=${process.env.FD_AUTH_COOKIE_PROD};`,
93
+ },
94
+ action: Permissions.AnyAuditLogs,
95
+ resource: {
96
+ id: "org12345",
97
+ type: "Org",
98
+ },
99
+ });
100
+
101
+ expect(authorizationResponse.status).toBe(200);
102
+ expect(authorizationResponse.data.authentication.authenticated).toBe(
103
+ true,
104
+ );
105
+ expect(authorizationResponse.data.authentication.principal?.type).toBe(
106
+ "User",
107
+ );
108
+ expect(authorizationResponse.data.authentication.principal?.id).toBe(
109
+ "8147747",
110
+ );
111
+ });
112
+
113
+ it("should not authenticate and authorize with an invalid FD-Authorization cookie", async () => {
114
+ try {
115
+ await authorization.authenticateAndAuthorize({
116
+ headers: {
117
+ Cookie: `FD-Authorization=not-a-valid-cookie;`,
118
+ },
119
+ action: Permissions.AnyAuditLogs,
120
+ resource: {
121
+ id: "org12345",
122
+ type: "Org",
123
+ },
124
+ });
125
+ } catch (error) {
126
+ if (isAxiosError<ErrorResponse>(error)) {
127
+ expect(error.response?.status).toBe(401);
128
+ expect(error.response?.data.message).toBe("Unauthenticated");
129
+ }
130
+ }
131
+ });
132
+
133
+ it("should authenticate and authorize with a valid Bearer token", async () => {
134
+ const authorizationResponse =
135
+ await authorization.authenticateAndAuthorize({
136
+ headers: {
137
+ Authorization: `Bearer ${process.env.FLIPDISH_BEARER_TOKEN_PROD}`,
138
+ },
139
+ action: Permissions.AnyAuditLogs,
140
+ resource: {
141
+ id: "org12345",
142
+ type: "Org",
143
+ },
144
+ });
145
+
146
+ expect(authorizationResponse.status).toBe(200);
147
+ expect(authorizationResponse.data.authentication.authenticated).toBe(
148
+ true,
149
+ );
150
+ expect(authorizationResponse.data.authentication.principal?.type).toBe(
151
+ "User",
152
+ );
153
+ expect(authorizationResponse.data.authentication.principal?.id).toBe(
154
+ "8147747",
155
+ );
156
+ });
157
+ });
158
+
159
+ test("Authorize", async () => {
160
+ const authorizationResponse = await authorization.authorize({
161
+ principal: {
162
+ id: "12345",
163
+ type: "User",
164
+ },
165
+ action: Permissions.AnyAuditLogs,
166
+ resource: {
167
+ id: "org12345",
168
+ type: "Org",
169
+ },
170
+ });
171
+ expect(authorizationResponse.status).toBe(200);
172
+ expect(authorizationResponse.data.allowed).toBe(false);
173
+ expect(authorizationResponse.data.decision).toBe("DENY");
174
+ });
175
+ });
139
176
  });
177
+
140
178
  ```
141
179
 
142
180
  The generated Node module can be used in the following environments:
package/configuration.ts CHANGED
@@ -100,7 +100,7 @@ export class Configuration {
100
100
 
101
101
  const extraHeaders = param.useDefaultUserAgent ? {} : {
102
102
  headers: {
103
- "user-agent": "Flipdish authorization typescript SDK / 0.1.9"
103
+ "user-agent": "Flipdish authorization typescript SDK / 0.2.0-rc.1760627866"
104
104
  }
105
105
  };
106
106
 
@@ -36,7 +36,7 @@ var Configuration = /** @class */ (function () {
36
36
  this.serverIndex = param.serverIndex;
37
37
  var extraHeaders = param.useDefaultUserAgent ? {} : {
38
38
  headers: {
39
- "user-agent": "Flipdish authorization typescript SDK / 0.1.9"
39
+ "user-agent": "Flipdish authorization typescript SDK / 0.2.0-rc.1760627866"
40
40
  }
41
41
  };
42
42
  this.baseOptions = __assign(__assign({}, extraHeaders), param.baseOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipdish/authorization",
3
- "version": "0.1.9",
3
+ "version": "0.2.0-rc.1760627866",
4
4
  "description": "OpenAPI client for @flipdish/authorization",
5
5
  "author": "OpenAPI-Generator Contributors",
6
6
  "repository": {