@sweepbright/api-client 0.30.4 → 0.30.6

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 (78) hide show
  1. package/dist/mockServer.js +27 -0
  2. package/dist/mockServer.js.map +1 -0
  3. package/dist/src/__tests__/auth.test.js +15 -0
  4. package/dist/src/__tests__/auth.test.js.map +1 -0
  5. package/dist/src/__tests__/channels.test.js +77 -0
  6. package/dist/src/__tests__/channels.test.js.map +1 -0
  7. package/dist/src/__tests__/contacts.test.js +61 -0
  8. package/dist/src/__tests__/contacts.test.js.map +1 -0
  9. package/dist/src/__tests__/estates.test.js +43 -0
  10. package/dist/src/__tests__/estates.test.js.map +1 -0
  11. package/dist/src/__tests__/leads.test.js +55 -0
  12. package/dist/src/__tests__/leads.test.js.map +1 -0
  13. package/dist/src/common/currencies.js +55 -0
  14. package/dist/src/common/currencies.js.map +1 -0
  15. package/dist/src/common/types.js +3 -0
  16. package/dist/src/common/types.js.map +1 -0
  17. package/dist/src/entities/office.js +9 -0
  18. package/dist/src/entities/office.js.map +1 -0
  19. package/dist/src/entities/property.js +220 -0
  20. package/dist/src/entities/property.js.map +1 -0
  21. package/dist/src/index.js +94 -0
  22. package/dist/src/index.js.map +1 -0
  23. package/dist/src/resources/channel_accounts.js +31 -0
  24. package/dist/src/resources/channel_accounts.js.map +1 -0
  25. package/dist/src/resources/channels.js +32 -0
  26. package/dist/src/resources/channels.js.map +1 -0
  27. package/dist/src/resources/companies.js +16 -0
  28. package/dist/src/resources/companies.js.map +1 -0
  29. package/dist/src/resources/contact_preferences.js +14 -0
  30. package/dist/src/resources/contact_preferences.js.map +1 -0
  31. package/dist/src/resources/contacts.js +29 -0
  32. package/dist/src/resources/contacts.js.map +1 -0
  33. package/dist/src/resources/estates.js +73 -0
  34. package/dist/src/resources/estates.js.map +1 -0
  35. package/dist/src/resources/leads.js +26 -0
  36. package/dist/src/resources/leads.js.map +1 -0
  37. package/dist/src/resources/negotiators.js +16 -0
  38. package/dist/src/resources/negotiators.js.map +1 -0
  39. package/dist/src/resources/offices.js +12 -0
  40. package/dist/src/resources/offices.js.map +1 -0
  41. package/dist/src/types.js +40 -0
  42. package/dist/src/types.js.map +1 -0
  43. package/dist/src/utils.js +28 -0
  44. package/dist/src/utils.js.map +1 -0
  45. package/package.json +7 -3
  46. package/.circleci/config.yml +0 -102
  47. package/.devcontainer/Dockerfile +0 -23
  48. package/.devcontainer/devcontainer.json +0 -59
  49. package/.editorconfig +0 -11
  50. package/.eslintrc.json +0 -6
  51. package/.github/PULL_REQUEST_TEMPLATE.md +0 -40
  52. package/.nvmrc +0 -1
  53. package/.prettierignore +0 -1
  54. package/jest.config.js +0 -7
  55. package/mockServer.ts +0 -44
  56. package/setupTests.ts +0 -1
  57. package/src/__tests__/auth.test.ts +0 -14
  58. package/src/__tests__/channels.test.ts +0 -104
  59. package/src/__tests__/contacts.test.ts +0 -85
  60. package/src/__tests__/estates.test.ts +0 -50
  61. package/src/__tests__/leads.test.ts +0 -67
  62. package/src/common/currencies.ts +0 -50
  63. package/src/common/types.ts +0 -1
  64. package/src/entities/office.ts +0 -193
  65. package/src/entities/property.ts +0 -574
  66. package/src/index.ts +0 -128
  67. package/src/resources/channel_accounts.ts +0 -39
  68. package/src/resources/channels.ts +0 -52
  69. package/src/resources/companies.ts +0 -15
  70. package/src/resources/contact_preferences.ts +0 -14
  71. package/src/resources/contacts.ts +0 -38
  72. package/src/resources/estates.ts +0 -145
  73. package/src/resources/leads.ts +0 -65
  74. package/src/resources/negotiators.ts +0 -19
  75. package/src/resources/offices.ts +0 -12
  76. package/src/types.ts +0 -88
  77. package/src/utils.ts +0 -35
  78. package/tsconfig.json +0 -19
@@ -1,59 +0,0 @@
1
- // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2
- // https://github.com/microsoft/vscode-dev-containers/tree/v0.202.5/containers/typescript-node
3
- {
4
- "name": "Node.js & TypeScript",
5
- "runArgs": [
6
- "--init"
7
- ],
8
- "build": {
9
- "dockerfile": "Dockerfile",
10
- // Update 'VARIANT' to pick a Node version: 16, 14, 12.
11
- // Append -bullseye or -buster to pin to an OS version.
12
- // Use -bullseye variants on local on arm64/Apple Silicon.
13
- "args": {
14
- "VARIANT": "14-bullseye"
15
- }
16
- },
17
- // Set *default* container specific settings.json values on container create.
18
- "settings": {},
19
- // Add the IDs of extensions you want installed when the container is created.
20
- "mounts": [
21
- //For deploying with Serverless
22
- "source=${localEnv:HOME}/.aws,target=/home/node/.aws,type=bind,consistency=cached"
23
- ],
24
- "extensions": [
25
- "dbaeumer.vscode-eslint",
26
- "maptz.regionfolder",
27
- "wmaurer.change-case",
28
- "jvandyke.vscode-circleci",
29
- "anseki.vscode-color",
30
- "nemesv.copy-file-name",
31
- "ryanluker.vscode-coverage-gutters",
32
- "aeschli.vscode-css-formatter",
33
- "jpruliere.env-autocomplete",
34
- "waderyan.gitblame",
35
- "github.vscode-pull-request-github",
36
- "eamodio.gitlens",
37
- "pushqrdx.inline-html",
38
- "orta.vscode-jest",
39
- "cmstead.js-codeformer",
40
- "eg2.vscode-npm-script",
41
- "silvenga.positions",
42
- "esbenp.prettier-vscode",
43
- "2gua.rainbow-brackets",
44
- "unional.vscode-sort-package-json",
45
- "hbenl.vscode-test-explorer"
46
- ],
47
- // Use 'forwardPorts' to make a list of ports inside the container available locally.
48
- "forwardPorts": [
49
- 3000,
50
- 3001
51
- ],
52
- // Use 'postCreateCommand' to run commands after the container is created.
53
- // "postCreateCommand": "yarn",
54
- // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
55
- "remoteUser": "node",
56
- "containerEnv": {
57
- "NPM_TOKEN": "${localEnv:NPM_TOKEN}"
58
- }
59
- }
package/.editorconfig DELETED
@@ -1,11 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = space
5
- indent_size = 2
6
- charset = utf-8
7
- trim_trailing_whitespace = true
8
- insert_final_newline = true
9
-
10
- [*.md]
11
- trim_trailing_whitespace = false
package/.eslintrc.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "extends": "@sweepbright/eslint-config-shared",
3
- "rules": {
4
- "@typescript-eslint/ban-ts-comment": "off"
5
- }
6
- }
@@ -1,40 +0,0 @@
1
- ### Add any information and/or comments that might be useful to your reviewer:
2
-
3
- *For example: what is the current behaviour?*
4
-
5
- *How has this change.*
6
-
7
- ---
8
- ### Please check the type of change your PR introduces:
9
- - [ ] Bugfix
10
- - [ ] Feature
11
- - [ ] CI improvement
12
- - [ ] Refactoring (no functional changes, no api changes)
13
- - [ ] Build related changes
14
- - [ ] Documentation content changes
15
- - [ ] Other (please describe)
16
- ---
17
- ### Checklist before requesting a review:
18
- - [ ] I have performed a self-review of my code
19
- - [ ] I have improved the technical debt/and not created more
20
- - [ ] I have increased test coverage.
21
- - [ ] I have made corresponding changes to the documentation or created an issue for this.
22
- - [ ] Changing documentation was not necessary - but I considered if it was important for this change.
23
- ---
24
- ### How has this been Tested?
25
- - [ ] WebApp
26
- - [ ] iOS
27
- - [ ] Android
28
- - [ ] Other - *need to comment*
29
-
30
- *I tested this by...*
31
-
32
- *going to...and typing/clicking...it can be reproduced by...*
33
-
34
- *creating the unit tests...*
35
-
36
- *see the images/video here that show...*
37
-
38
- *I consider the edge cases...*
39
-
40
- *I know my tests don't cover...*
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- 16
package/.prettierignore DELETED
@@ -1 +0,0 @@
1
- dist
package/jest.config.js DELETED
@@ -1,7 +0,0 @@
1
- /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
- module.exports = {
3
- preset: "ts-jest",
4
- testEnvironment: "node",
5
- testTimeout: 30000,
6
- setupFilesAfterEnv: ['./setupTests.ts'],
7
- };
package/mockServer.ts DELETED
@@ -1,44 +0,0 @@
1
- import { rest } from 'msw';
2
- import { setupServer } from 'msw/node';
3
-
4
- const server = setupServer(
5
- rest.post('*', (req, res, ctx) => {
6
- return res(
7
- ctx.status(500),
8
- ctx.json({ error: 'Mock this request ' + req.url.toString() })
9
- );
10
- }),
11
- rest.get('*', (req, res, ctx) => {
12
- return res(
13
- ctx.status(500),
14
- ctx.json({ error: 'Mock this request ' + req.url.toString() })
15
- );
16
- }),
17
- rest.put('*', (req, res, ctx) => {
18
- return res(
19
- ctx.status(500),
20
- ctx.json({ error: 'Mock this request ' + req.url.toString() })
21
- );
22
- })
23
- );
24
-
25
- beforeAll(() => server.listen());
26
- afterAll(() => server.close());
27
- beforeEach(() => server.resetHandlers());
28
-
29
- const handlers = {
30
- authHandler: rest.post(
31
- 'https://api.sweepbright.com/auth/access-token',
32
- (_req, res, ctx) => {
33
- return res(
34
- ctx.status(200),
35
- ctx.json({
36
- access_token: 'FAKE_TOKEN',
37
- expires_in: Date.now(),
38
- })
39
- );
40
- }
41
- ),
42
- };
43
-
44
- export { server, rest, handlers };
package/setupTests.ts DELETED
@@ -1 +0,0 @@
1
- import './mockServer';
@@ -1,14 +0,0 @@
1
- import { createClient } from '../';
2
- import { handlers, server } from '../../mockServer';
3
-
4
- describe('authorization', () => {
5
- it('can fetch an auth token', async () => {
6
- const client = createClient({
7
- clientId: 'FAKE_ID',
8
- clientSecret: 'FAKE_SECRET',
9
- });
10
-
11
- server.use(handlers.authHandler);
12
- await client.authorize({});
13
- });
14
- });
@@ -1,104 +0,0 @@
1
- import { createClient } from '../';
2
- import { handlers, rest, server } from '../../mockServer';
3
-
4
- describe('channels', () => {
5
- it('can fetch a references list', async () => {
6
- const client = createClient({
7
- clientId: 'FAKE_ID',
8
- clientSecret: 'FAKE_SECRET',
9
- });
10
- server.use(handlers.authHandler);
11
- await client.authorize();
12
-
13
- const estateId = 'FAKE_ESTATE_ID';
14
- const reference = 'FAKE_REFERENCE';
15
- const channelAccountId = 'FAKE_CHANNEL_ACCOUNT_ID';
16
- const companyId = 'FAKE_COMPANY_ID';
17
- const channelId = 'FAKE_CHANNEL_ID';
18
-
19
- server.use(
20
- rest.get(
21
- 'https://api.sweepbright.com/services/channel-references',
22
- (req, res, ctx) => {
23
- return res(
24
- ctx.status(200),
25
- ctx.json({
26
- data: [
27
- {
28
- reference_code: req.url.searchParams.get('reference_code'),
29
- company_id: req.url.searchParams.get('company_id'),
30
- channel_id: req.url.searchParams.get('channel_id'),
31
- estate_id: estateId,
32
- channel_account_id: channelAccountId,
33
- },
34
- ],
35
- })
36
- );
37
- }
38
- )
39
- );
40
-
41
- const result = await client.channels.resolveReferences(
42
- channelId,
43
- reference,
44
- companyId
45
- );
46
- expect(result).toEqual({
47
- data: [
48
- {
49
- reference_code: reference,
50
- estate_id: estateId,
51
- channel_account_id: channelAccountId,
52
- channel_id: channelId,
53
- company_id: companyId,
54
- },
55
- ],
56
- });
57
- });
58
-
59
- it('it does not send a company_id when not set', async () => {
60
- const client = createClient({
61
- clientId: 'FAKE_ID',
62
- clientSecret: 'FAKE_SECRET',
63
- });
64
- server.use(handlers.authHandler);
65
- await client.authorize();
66
-
67
- const estateId = 'FAKE_ESTATE_ID';
68
- const reference = 'FAKE_REFERENCE';
69
- const channelAccountId = 'FAKE_CHANNEL_ACCOUNT_ID';
70
- const channelId = 'FAKE_CHANNEL_ID';
71
-
72
- server.use(
73
- rest.get(
74
- 'https://api.sweepbright.com/services/channel-references',
75
- (req, res, ctx) => {
76
- try {
77
- expect(req.url.search).toEqual(
78
- `?channel_id=${channelId}&reference_code=${reference}`
79
- );
80
- } catch (e) {
81
- return res(ctx.status(500), ctx.json({ error: e }));
82
- }
83
-
84
- return res(
85
- ctx.status(200),
86
- ctx.json({
87
- data: [
88
- {
89
- reference_code: req.url.searchParams.get('reference_code'),
90
- company_id: 'FAKE',
91
- channel_id: req.url.searchParams.get('channel_id'),
92
- estate_id: estateId,
93
- channel_account_id: channelAccountId,
94
- },
95
- ],
96
- })
97
- );
98
- }
99
- )
100
- );
101
-
102
- await client.channels.resolveReferences(channelId, reference, undefined);
103
- });
104
- });
@@ -1,85 +0,0 @@
1
- import { createClient } from '../';
2
- import { handlers, rest, server } from '../../mockServer';
3
-
4
- describe('contacts', () => {
5
- it('requires authentication', async () => {
6
- const client = createClient({
7
- clientId: 'FAKE_ID',
8
- clientSecret: 'FAKE_SECRET',
9
- });
10
-
11
- try {
12
- await client.contacts.getOne({
13
- contactId: 'foo',
14
- });
15
- } catch (err: any) {
16
- expect(err.message).toEqual('client is not authenticated');
17
- }
18
- });
19
-
20
- it('can fetch a contact', async () => {
21
- const client = createClient({
22
- clientId: 'FAKE_ID',
23
- clientSecret: 'FAKE_SECRET',
24
- });
25
-
26
- server.use(handlers.authHandler);
27
- await client.authorize();
28
-
29
- const contactId = 'FAKE_CONTACT_ID';
30
- server.use(
31
- rest.get(
32
- 'https://api.sweepbright.com/services/contacts/:contactId',
33
- (req, res, ctx) => {
34
- return res(
35
- ctx.status(200),
36
- ctx.json({
37
- data: {
38
- id: req.params.contactId,
39
- },
40
- })
41
- );
42
- }
43
- )
44
- );
45
-
46
- const result = await client.contacts.getOne({
47
- contactId: contactId,
48
- });
49
-
50
- expect(result).toEqual({ data: { id: contactId } });
51
- });
52
-
53
- it('can fetch a contact with negotiators', async () => {
54
- const client = createClient({
55
- clientId: 'FAKE_ID',
56
- clientSecret: 'FAKE_SECRET',
57
- });
58
-
59
- server.use(handlers.authHandler);
60
- await client.authorize();
61
-
62
- const contactId = 'FAKE_CONTACT_ID';
63
- server.use(
64
- rest.get(
65
- 'https://api.sweepbright.com/services/contacts/:contactId?includes=negotiators',
66
- (req, res, ctx) => {
67
- return res(
68
- ctx.status(200),
69
- ctx.json({
70
- data: {
71
- id: req.params.contactId,
72
- },
73
- })
74
- );
75
- }
76
- )
77
- );
78
-
79
- const result = await client.contacts.getOneWithNegotiators({
80
- contactId: contactId,
81
- });
82
-
83
- expect(result).toEqual({ data: { id: contactId } });
84
- });
85
- });
@@ -1,50 +0,0 @@
1
- import { createClient } from '../';
2
- import { handlers, rest, server } from '../../mockServer';
3
-
4
- describe('estates', () => {
5
- it('requires authentication', async () => {
6
- const client = createClient({
7
- clientId: 'FAKE_ID',
8
- clientSecret: 'FAKE_SECRET',
9
- });
10
- try {
11
- await client.estates.getOne({
12
- estateId: 'FAKE_ESTATE_ID',
13
- companyId: 'FAKE_COMPANY_ID',
14
- });
15
- } catch (err) {
16
- await expect((err as any).message).toEqual('client is not authenticated');
17
- }
18
- });
19
-
20
- it('can fetch a estate', async () => {
21
- const client = createClient({
22
- clientId: 'FAKE_ID',
23
- clientSecret: 'FAKE_SECRET',
24
- });
25
- server.use(handlers.authHandler);
26
- await client.authorize();
27
-
28
- const estateId = 'FAKE_ESTATE_ID';
29
- server.use(
30
- rest.get(
31
- 'https://api.sweepbright.com/services/estates/:estateId',
32
- (req, res, ctx) => {
33
- return res(
34
- ctx.status(200),
35
- ctx.json({
36
- data: {
37
- id: req.params.estateId,
38
- },
39
- })
40
- );
41
- }
42
- )
43
- );
44
- const result = await client.estates.getOne({
45
- estateId: estateId,
46
- companyId: 'FAKE_COMPANY_ID',
47
- });
48
- expect(result).toEqual({ id: estateId });
49
- });
50
- });
@@ -1,67 +0,0 @@
1
- import { createClient } from '../';
2
- import { handlers, rest, server } from '../../mockServer';
3
-
4
- describe('leads', () => {
5
- it('requires authentication', async () => {
6
- const client = createClient({
7
- clientId: 'FAKE_ID',
8
- clientSecret: 'FAKE_SECRET',
9
- });
10
-
11
- try {
12
- await client.leads.createLead({
13
- firstName: 'foo',
14
- lastName: 'bar',
15
- propertyId: 'baz',
16
- email: 'john@example.com',
17
- phone: '999',
18
- message: "I'm not authenticated",
19
- portal: 'portal',
20
- });
21
- } catch (err: any) {
22
- expect(err.message).toEqual('client is not authenticated');
23
- }
24
- });
25
-
26
- it('can put a lead', async () => {
27
- const client = createClient({
28
- clientId: 'FAKE_ID',
29
- clientSecret: 'FAKE_SECRET',
30
- });
31
-
32
- server.use(handlers.authHandler);
33
- await client.authorize();
34
-
35
- const lead = {
36
- firstName: 'foo',
37
- lastName: 'bar',
38
- propertyId: 'PROPERTY_ID',
39
- email: 'john@example.com',
40
- phone: '999',
41
- message: "I'm authenticated",
42
- portal: 'portal',
43
- location_preference: {
44
- country: 'BR',
45
- postal_codes: ['06010'],
46
- },
47
- };
48
-
49
- server.use(
50
- rest.put(
51
- 'https://api.sweepbright.com/estates/PROPERTY_ID/leads',
52
- (_, res, ctx) => {
53
- return res(
54
- ctx.status(200),
55
- ctx.json({
56
- data: lead,
57
- })
58
- );
59
- }
60
- )
61
- );
62
-
63
- const result = await client.leads.createLead(lead);
64
-
65
- expect(result).toEqual({ data: lead });
66
- });
67
- });
@@ -1,50 +0,0 @@
1
- export enum Currency {
2
- EUR = 'EUR',
3
- AUD = 'AUD',
4
- USD = 'USD',
5
- AFN = 'AFN',
6
- GBP = 'GBP',
7
- XPF = 'XPF',
8
- MXN = 'MXN',
9
- PHP = 'PHP',
10
- CAD = 'CAD',
11
- RON = 'RON',
12
- BRL = 'BRL',
13
- UYU = 'UYU',
14
- HRK = 'HRK',
15
- GEL = 'GEL',
16
- RSD = 'RSD',
17
- ILS = 'ILS',
18
- ARS = 'ARS',
19
- NZD = 'NZD',
20
- ZAR = 'ZAR',
21
- INR = 'INR',
22
- DZD = 'DZD',
23
- LKR = 'LKR',
24
- CLP = 'CLP',
25
- ALL = 'ALL',
26
- RUB = 'RUB',
27
- TRY = 'TRY',
28
- UAH = 'UAH',
29
- MUR = 'MUR',
30
- COP = 'COP',
31
- AED = 'AED',
32
- MZN = 'MZN',
33
- EGP = 'EGP',
34
- AOA = 'AOA',
35
- XOF = 'XOF',
36
- CNY = 'CNY',
37
- XCD = 'XCD',
38
- VND = 'VND',
39
- JPY = 'JPY',
40
- MAD = 'MAD',
41
- CHF = 'CHF',
42
- IRR = 'IRR',
43
- KHR = 'KHR',
44
- XAF = 'XAF',
45
- AMD = 'AMD',
46
- ETB = 'ETB',
47
- SGD = 'SGD',
48
- NGN = 'NGN',
49
- PKP = 'PKP',
50
- }
@@ -1 +0,0 @@
1
- export type Maybe<T> = T | null | undefined;