@sweepbright/api-client 0.31.6 → 0.31.8-pre-release.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.
- package/dist/common/currencies.d.ts +50 -0
- package/dist/common/currencies.js +55 -0
- package/dist/common/currencies.js.map +1 -0
- package/dist/common/envHosts.d.ts +2 -0
- package/dist/common/envHosts.js +10 -0
- package/dist/common/envHosts.js.map +1 -0
- package/dist/common/types.d.ts +1 -0
- package/dist/common/types.js +3 -0
- package/dist/common/types.js.map +1 -0
- package/dist/entities/negotiator.d.ts +11 -0
- package/dist/entities/negotiator.js +3 -0
- package/dist/entities/negotiator.js.map +1 -0
- package/dist/entities/office.d.ts +16 -0
- package/dist/entities/office.js +9 -0
- package/dist/entities/office.js.map +1 -0
- package/dist/entities/property.d.ts +516 -0
- package/dist/entities/property.js +220 -0
- package/dist/entities/property.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +124 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth-manager/AuthenticationService_PrivateAPI.d.ts +20 -0
- package/dist/oauth-manager/AuthenticationService_PrivateAPI.js +54 -0
- package/dist/oauth-manager/AuthenticationService_PrivateAPI.js.map +1 -0
- package/dist/oauth-manager/OAuthManager_Impl.d.ts +10 -0
- package/dist/oauth-manager/OAuthManager_Impl.js +96 -0
- package/dist/oauth-manager/OAuthManager_Impl.js.map +1 -0
- package/dist/oauth-manager/SessionDataImpl.d.ts +18 -0
- package/dist/oauth-manager/SessionDataImpl.js +47 -0
- package/dist/oauth-manager/SessionDataImpl.js.map +1 -0
- package/dist/oauth-manager/TokensRepository_Memory.d.ts +8 -0
- package/dist/oauth-manager/TokensRepository_Memory.js +102 -0
- package/dist/oauth-manager/TokensRepository_Memory.js.map +1 -0
- package/dist/oauth-manager/TokensRepository_Redis.d.ts +13 -0
- package/dist/oauth-manager/TokensRepository_Redis.js +69 -0
- package/dist/oauth-manager/TokensRepository_Redis.js.map +1 -0
- package/dist/oauth-manager/factories/createOAuthManager.d.ts +16 -0
- package/dist/oauth-manager/factories/createOAuthManager.js +23 -0
- package/dist/oauth-manager/factories/createOAuthManager.js.map +1 -0
- package/dist/oauth-manager/interfaces.d.ts +56 -0
- package/dist/oauth-manager/interfaces.js +3 -0
- package/dist/oauth-manager/interfaces.js.map +1 -0
- package/dist/oauth-manager/playground/main.d.ts +1 -0
- package/dist/oauth-manager/playground/main.js +42 -0
- package/dist/oauth-manager/playground/main.js.map +1 -0
- package/dist/resources/channel_accounts.d.ts +15 -0
- package/dist/resources/channel_accounts.js +31 -0
- package/dist/resources/channel_accounts.js.map +1 -0
- package/dist/resources/channels.d.ts +16 -0
- package/dist/resources/channels.js +32 -0
- package/dist/resources/channels.js.map +1 -0
- package/dist/resources/companies.d.ts +7 -0
- package/dist/resources/companies.js +16 -0
- package/dist/resources/companies.js.map +1 -0
- package/dist/resources/contact_preferences.d.ts +6 -0
- package/dist/resources/contact_preferences.js +14 -0
- package/dist/resources/contact_preferences.js.map +1 -0
- package/dist/resources/contacts.d.ts +14 -0
- package/dist/resources/contacts.js +29 -0
- package/dist/resources/contacts.js.map +1 -0
- package/dist/resources/estates.d.ts +43 -0
- package/dist/resources/estates.js +73 -0
- package/dist/resources/estates.js.map +1 -0
- package/dist/resources/leads.d.ts +39 -0
- package/dist/resources/leads.js +26 -0
- package/dist/resources/leads.js.map +1 -0
- package/dist/resources/negotiators.d.ts +9 -0
- package/dist/resources/negotiators.js +16 -0
- package/dist/resources/negotiators.js.map +1 -0
- package/dist/resources/offices.d.ts +8 -0
- package/dist/resources/offices.js +19 -0
- package/dist/resources/offices.js.map +1 -0
- package/dist/schemas/currenciesSchema.d.ts +3 -0
- package/dist/schemas/currenciesSchema.js +8 -0
- package/dist/schemas/currenciesSchema.js.map +1 -0
- package/dist/schemas/officeSchema.d.ts +7459 -0
- package/dist/schemas/officeSchema.js +214 -0
- package/dist/schemas/officeSchema.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.js +40 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -0
- package/package.json +9 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionDataImpl.js","sourceRoot":"","sources":["../../src/oauth-manager/SessionDataImpl.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AASpC,SAAS,SAAS,CAAC,CAAS;IAC1B,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,MAAa,eAAe;IAK1B,YAAY,OAA+B;QACzC,IAAI,CAAC,WAAW,GAAG;YACjB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;SACnC,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAE7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IACD,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IACD,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEO,eAAe,CAAC,MAAyB;QAC/C,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;QACpE,gBAAgB,CAAC,IAAI,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC/C,CAAC;IAEO,SAAS,CAAC,OAA+B;QAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAElC,MAAM,gBAAgB,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAE9D,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QAE5D,MAAM,YAAY,GAAG,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEhD,6CAA6C;QAC7C,2EAA2E;QAC3E,wDAAwD;QACxD,mEAAmE;QACnE,EAAE;QACF,kFAAkF;QAClF,iCAAiC;QACjC,OAAO,GAAG,QAAQ,IAAI,UAAU,IAAI,YAAY,EAAE,CAAC;IACrD,CAAC;CACF;AAlDD,0CAkDC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LockAcquireOptions, LockId, LockReleaseOptions, TokensRepository } from './interfaces';
|
|
2
|
+
export declare class TokensRepository_Memory implements TokensRepository {
|
|
3
|
+
private records;
|
|
4
|
+
getAccessTokenIfValid(sessionKey: string, currentTime: Date): Promise<string | null>;
|
|
5
|
+
deleteAccessToken(lockId: LockId, sessionKey: string): Promise<void>;
|
|
6
|
+
acquireLock(options: LockAcquireOptions): Promise<LockId | null>;
|
|
7
|
+
releaseLock(lockId: LockId, options: LockReleaseOptions): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokensRepository_Memory = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const globalRecords = new Map();
|
|
6
|
+
class TokensRepository_Memory {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.records = globalRecords;
|
|
9
|
+
}
|
|
10
|
+
async getAccessTokenIfValid(sessionKey, currentTime) {
|
|
11
|
+
// "Valid" means the following:
|
|
12
|
+
// - A record exists for the given `channelAccountID`
|
|
13
|
+
// - The `accessToken` is not null
|
|
14
|
+
// - The `expires_at` is in the future
|
|
15
|
+
const record = this.records.get(sessionKey);
|
|
16
|
+
if (!record) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const { accessToken, expiresAt } = record;
|
|
20
|
+
if (!accessToken || !expiresAt) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (expiresAt < currentTime) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return accessToken;
|
|
27
|
+
}
|
|
28
|
+
async deleteAccessToken(lockId, sessionKey) {
|
|
29
|
+
const existingRecord = this.records.get(sessionKey);
|
|
30
|
+
if (!existingRecord) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!existingRecord.lockId) {
|
|
34
|
+
throw new Error('Cannot delete access token, not locked');
|
|
35
|
+
}
|
|
36
|
+
if (existingRecord.lockId !== lockId) {
|
|
37
|
+
throw new Error('Cannot delete access token, locked by another process');
|
|
38
|
+
}
|
|
39
|
+
this.records.set(sessionKey, {
|
|
40
|
+
...existingRecord,
|
|
41
|
+
accessToken: null,
|
|
42
|
+
expiresAt: null,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async acquireLock(options) {
|
|
46
|
+
//To acquire lock means to set the `locked_until` to the current time + lock TTL (10 sec)
|
|
47
|
+
//If the `locked_until` is already set and it's in the future, the lock is considered already acquired and we should return false
|
|
48
|
+
//If the `locked_until` is already set and it's in the past, the lock is expired and can be acquired again
|
|
49
|
+
const existingRecord = this.records.get(options.sessionKey);
|
|
50
|
+
if (!existingRecord) {
|
|
51
|
+
const lockId = (0, uuid_1.v4)();
|
|
52
|
+
// Create a new record
|
|
53
|
+
this.records.set(options.sessionKey, {
|
|
54
|
+
accessToken: null,
|
|
55
|
+
expiresAt: null,
|
|
56
|
+
lockedUntil: options.lockedUntil,
|
|
57
|
+
lockId,
|
|
58
|
+
});
|
|
59
|
+
return lockId;
|
|
60
|
+
}
|
|
61
|
+
const { lockedUntil } = existingRecord;
|
|
62
|
+
const isStillLocked = lockedUntil && lockedUntil > new Date();
|
|
63
|
+
if (isStillLocked) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const lockId = (0, uuid_1.v4)();
|
|
67
|
+
// Update the record
|
|
68
|
+
this.records.set(options.sessionKey, {
|
|
69
|
+
...existingRecord,
|
|
70
|
+
lockedUntil: options.lockedUntil,
|
|
71
|
+
lockId,
|
|
72
|
+
});
|
|
73
|
+
return lockId;
|
|
74
|
+
}
|
|
75
|
+
async releaseLock(lockId, options) {
|
|
76
|
+
console.log('releasing lock');
|
|
77
|
+
const existingRecord = this.records.get(options.sessionKey);
|
|
78
|
+
if (!existingRecord) {
|
|
79
|
+
throw new Error('No record found');
|
|
80
|
+
}
|
|
81
|
+
if (existingRecord.lockId !== lockId) {
|
|
82
|
+
throw new Error('Cannot release lock, because it was set by another process');
|
|
83
|
+
}
|
|
84
|
+
if (!options.shouldUpdateTokens) {
|
|
85
|
+
this.records.set(options.sessionKey, {
|
|
86
|
+
...existingRecord,
|
|
87
|
+
lockedUntil: null,
|
|
88
|
+
lockId: null,
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.records.set(options.sessionKey, {
|
|
93
|
+
...existingRecord,
|
|
94
|
+
accessToken: options.tokens.accessToken,
|
|
95
|
+
expiresAt: options.expiresAt,
|
|
96
|
+
lockedUntil: null,
|
|
97
|
+
lockId: null,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.TokensRepository_Memory = TokensRepository_Memory;
|
|
102
|
+
//# sourceMappingURL=TokensRepository_Memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokensRepository_Memory.js","sourceRoot":"","sources":["../../src/oauth-manager/TokensRepository_Memory.ts"],"names":[],"mappings":";;;AAAA,+BAA0B;AAe1B,MAAM,aAAa,GAA8B,IAAI,GAAG,EAAE,CAAC;AAE3D,MAAa,uBAAuB;IAAp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AG,cAAc;gBACjB,WAAW,EAAE,IAAI;gBACjB,MAAM,EAAE,IAAI;aACb,CAAC,CAAC;YACH,OAAO;SACR;QAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE;YACnC,GAAG,cAAc;YACjB,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW;YACvC,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,WAAW,EAAE,IAAI;YACjB,MAAM,EAAE,IAAI;SACb,CAAC,CAAC;IACL,CAAC;CACF;AArHD,0DAqHC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Redis } from 'ioredis';
|
|
2
|
+
import { LockAcquireOptions, LockId, LockReleaseOptions, TokensRepository } from './interfaces';
|
|
3
|
+
export declare class TokensRepository_Redis implements TokensRepository {
|
|
4
|
+
private readonly redis;
|
|
5
|
+
constructor(redis: Redis);
|
|
6
|
+
private readonly version;
|
|
7
|
+
private accessTokenKey;
|
|
8
|
+
private lockKey;
|
|
9
|
+
getAccessTokenIfValid(sessionKey: string, currentTime: Date): Promise<string | null>;
|
|
10
|
+
deleteAccessToken(lockId: LockId, sessionKey: string): Promise<void>;
|
|
11
|
+
acquireLock(options: LockAcquireOptions): Promise<LockId | null>;
|
|
12
|
+
releaseLock(lockId: LockId, options: LockReleaseOptions): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokensRepository_Redis = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
class TokensRepository_Redis {
|
|
6
|
+
constructor(redis) {
|
|
7
|
+
this.redis = redis;
|
|
8
|
+
this.version = 'v1';
|
|
9
|
+
}
|
|
10
|
+
accessTokenKey(sessionKey) {
|
|
11
|
+
return `${this.version}/${sessionKey}/t`;
|
|
12
|
+
}
|
|
13
|
+
lockKey(sessionKey) {
|
|
14
|
+
return `${this.version}/${sessionKey}/l`;
|
|
15
|
+
}
|
|
16
|
+
getAccessTokenIfValid(sessionKey,
|
|
17
|
+
//eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
+
currentTime) {
|
|
19
|
+
// If a record exists, the record is valid.
|
|
20
|
+
// Expiration is provided automatically by Redis.
|
|
21
|
+
return this.redis.get(this.accessTokenKey(sessionKey));
|
|
22
|
+
}
|
|
23
|
+
async deleteAccessToken(lockId, sessionKey) {
|
|
24
|
+
const existingLock = await this.redis.get(this.lockKey(sessionKey));
|
|
25
|
+
if (!existingLock) {
|
|
26
|
+
throw new Error('Cannot delete access token, not locked');
|
|
27
|
+
}
|
|
28
|
+
if (existingLock !== lockId) {
|
|
29
|
+
throw new Error('Cannot delete access token, locked by another process');
|
|
30
|
+
}
|
|
31
|
+
await this.redis.del(this.accessTokenKey(sessionKey));
|
|
32
|
+
}
|
|
33
|
+
async acquireLock(options) {
|
|
34
|
+
const { sessionKey, lockedUntil, currentTime } = options;
|
|
35
|
+
const lockId = (0, uuid_1.v4)();
|
|
36
|
+
const result = await this.redis.set(this.lockKey(sessionKey), lockId, 'PX', // PX means "TTL in milliseconds"
|
|
37
|
+
lockedUntil.getTime() - currentTime.getTime(), 'NX' // NX means "only set record if not exists"
|
|
38
|
+
);
|
|
39
|
+
//Lock acquired
|
|
40
|
+
if (result === 'OK') {
|
|
41
|
+
return lockId;
|
|
42
|
+
}
|
|
43
|
+
//Lock not acquired, because another process has already acquired the lock
|
|
44
|
+
if (result === null) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
//Normally this should never happen
|
|
48
|
+
throw new Error(`Unknown response from Redis: ${result}`);
|
|
49
|
+
}
|
|
50
|
+
async releaseLock(lockId, options) {
|
|
51
|
+
const { sessionKey, shouldUpdateTokens } = options;
|
|
52
|
+
const existingLockId = await this.redis.get(this.lockKey(sessionKey));
|
|
53
|
+
if (existingLockId !== lockId) {
|
|
54
|
+
throw new Error('Cannot release lock, because it was set by another process');
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
if (shouldUpdateTokens) {
|
|
58
|
+
const { tokens: { accessToken }, expiresAt, currentTime, } = options;
|
|
59
|
+
await this.redis.set(this.accessTokenKey(sessionKey), accessToken, 'PX', // PX means "TTL in milliseconds"
|
|
60
|
+
expiresAt.getTime() - currentTime.getTime());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
await this.redis.del(this.lockKey(sessionKey));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.TokensRepository_Redis = TokensRepository_Redis;
|
|
69
|
+
//# sourceMappingURL=TokensRepository_Redis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokensRepository_Redis.js","sourceRoot":"","sources":["../../src/oauth-manager/TokensRepository_Redis.ts"],"names":[],"mappings":";;;AACA,+BAA0B;AAQ1B,MAAa,sBAAsB;IACjC,YAA6B,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;QAExB,YAAO,GAAG,IAAI,CAAC;IAFY,CAAC;IAIrC,cAAc,CAAC,UAAkB;QACvC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,UAAU,IAAI,CAAC;IAC3C,CAAC;IAEO,OAAO,CAAC,UAAkB;QAChC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,UAAU,IAAI,CAAC;IAC3C,CAAC;IAED,qBAAqB,CACnB,UAAkB;IAClB,4DAA4D;IAC5D,WAAiB;QAEjB,2CAA2C;QAC3C,iDAAiD;QACjD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,MAAc,EAAE,UAAkB;QACxD,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CA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,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;SACH;QAED,IAAI;YACF,IAAI,kBAAkB,EAAE;gBACtB,MAAM,EACJ,MAAM,EAAE,EAAE,WAAW,EAAE,EACvB,SAAS,EACT,WAAW,GACZ,GAAG,OAAO,CAAC;gBAEZ,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAClB,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAC/B,WAAW,EACX,IAAI,EAAE,iCAAiC;gBACvC,SAAS,CAAC,OAAO,EAAE,GAAG,WAAW,CAAC,OAAO,EAAE,CAC5C,CAAC;aACH;SACF;gBAAS;YACR,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;SAChD;IACH,CAAC;CACF;AA1FD,wDA0FC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Env } from '../../types';
|
|
2
|
+
import { OAuthManager } from '../interfaces';
|
|
3
|
+
interface CreateOAuthManagerOptionsRedis {
|
|
4
|
+
env: Env;
|
|
5
|
+
apiVersion: string;
|
|
6
|
+
storage: 'redis';
|
|
7
|
+
redisURL: string;
|
|
8
|
+
}
|
|
9
|
+
interface CreateOAuthManagerOptionsMemory {
|
|
10
|
+
env: Env;
|
|
11
|
+
apiVersion: string;
|
|
12
|
+
storage: 'memory';
|
|
13
|
+
}
|
|
14
|
+
type CreateOAuthManagerOptions = CreateOAuthManagerOptionsRedis | CreateOAuthManagerOptionsMemory;
|
|
15
|
+
export declare function createOAuthManager(opt: CreateOAuthManagerOptions): OAuthManager;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOAuthManager = void 0;
|
|
4
|
+
const assert_1 = require("assert");
|
|
5
|
+
const ioredis_1 = require("ioredis");
|
|
6
|
+
const envHosts_1 = require("../../common/envHosts");
|
|
7
|
+
const AuthenticationService_PrivateAPI_1 = require("../AuthenticationService_PrivateAPI");
|
|
8
|
+
const OAuthManager_Impl_1 = require("../OAuthManager_Impl");
|
|
9
|
+
const TokensRepository_Memory_1 = require("../TokensRepository_Memory");
|
|
10
|
+
const TokensRepository_Redis_1 = require("../TokensRepository_Redis");
|
|
11
|
+
function createOAuthManager(opt) {
|
|
12
|
+
const { env, apiVersion, storage } = opt;
|
|
13
|
+
const baseUrl = envHosts_1.envHosts[env];
|
|
14
|
+
(0, assert_1.ok)(baseUrl, 'baseUrl should be defined');
|
|
15
|
+
const tokensRepository = storage === 'redis'
|
|
16
|
+
? new TokensRepository_Redis_1.TokensRepository_Redis(new ioredis_1.Redis(opt.redisURL))
|
|
17
|
+
: storage === 'memory'
|
|
18
|
+
? new TokensRepository_Memory_1.TokensRepository_Memory()
|
|
19
|
+
: (0, assert_1.fail)('unknown storage');
|
|
20
|
+
return new OAuthManager_Impl_1.OAuthManager_Impl(tokensRepository, new AuthenticationService_PrivateAPI_1.AuthenticationService_PrivateAPI({ baseUrl, apiVersion }));
|
|
21
|
+
}
|
|
22
|
+
exports.createOAuthManager = createOAuthManager;
|
|
23
|
+
//# sourceMappingURL=createOAuthManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOAuthManager.js","sourceRoot":"","sources":["../../../src/oauth-manager/factories/createOAuthManager.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,qCAAgC;AAChC,oDAAiD;AAEjD,0FAAuF;AACvF,4DAAyD;AACzD,wEAAqE;AACrE,sEAAmE;AAkBnE,SAAgB,kBAAkB,CAChC,GAA8B;IAE9B,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAEzC,MAAM,OAAO,GAAG,mBAAQ,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAA,WAAE,EAAC,OAAO,EAAE,2BAA2B,CAAC,CAAC;IAEzC,MAAM,gBAAgB,GACpB,OAAO,KAAK,OAAO;QACjB,CAAC,CAAC,IAAI,+CAAsB,CAAC,IAAI,eAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACrD,CAAC,CAAC,OAAO,KAAK,QAAQ;YACtB,CAAC,CAAC,IAAI,iDAAuB,EAAE;YAC/B,CAAC,CAAC,IAAA,aAAI,EAAC,iBAAiB,CAAC,CAAC;IAE9B,OAAO,IAAI,qCAAiB,CAC1B,gBAAgB,EAChB,IAAI,mEAAgC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAC9D,CAAC;AACJ,CAAC;AAnBD,gDAmBC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
type Scopes = readonly string[];
|
|
2
|
+
export interface ClientCredentials {
|
|
3
|
+
readonly clientId: string;
|
|
4
|
+
readonly clientSecret: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SessionData {
|
|
7
|
+
getCredentials(): ClientCredentials;
|
|
8
|
+
getSessionKey(): string;
|
|
9
|
+
getScopes(): Scopes;
|
|
10
|
+
}
|
|
11
|
+
export interface Tokens {
|
|
12
|
+
accessToken: string;
|
|
13
|
+
expiresIn: number;
|
|
14
|
+
}
|
|
15
|
+
export interface LockAcquireOptions {
|
|
16
|
+
sessionKey: string;
|
|
17
|
+
lockedUntil: Date;
|
|
18
|
+
currentTime: Date;
|
|
19
|
+
}
|
|
20
|
+
interface LockReleaseOptionsWithTokens {
|
|
21
|
+
shouldUpdateTokens: true;
|
|
22
|
+
sessionKey: string;
|
|
23
|
+
tokens: Tokens;
|
|
24
|
+
expiresAt: Date;
|
|
25
|
+
currentTime: Date;
|
|
26
|
+
}
|
|
27
|
+
interface LockReleaseOptionsWithoutTokens {
|
|
28
|
+
shouldUpdateTokens: false;
|
|
29
|
+
sessionKey: string;
|
|
30
|
+
}
|
|
31
|
+
export type LockReleaseOptions = LockReleaseOptionsWithTokens | LockReleaseOptionsWithoutTokens;
|
|
32
|
+
export type LockId = string;
|
|
33
|
+
export interface TokensRepository {
|
|
34
|
+
getAccessTokenIfValid(sessionKey: string, currentTime: Date): Promise<string | null>;
|
|
35
|
+
deleteAccessToken(lockId: LockId, sessionKey: string): Promise<void>;
|
|
36
|
+
acquireLock(options: LockAcquireOptions): Promise<LockId | null>;
|
|
37
|
+
releaseLock(lockId: LockId, options: LockReleaseOptions): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* AuthenticationService is used for authentication
|
|
41
|
+
* (exchanging the client credentials for an access token)
|
|
42
|
+
*/
|
|
43
|
+
export interface AuthenticationService {
|
|
44
|
+
authenticate(sessionData: SessionData): Promise<Tokens | null>;
|
|
45
|
+
}
|
|
46
|
+
export interface GetAccessTokenOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Ignore and delete the existing token, if any.
|
|
49
|
+
* Only enable this option if your previous API request resulted with a 401.
|
|
50
|
+
*/
|
|
51
|
+
forceInvalidate?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface OAuthManager {
|
|
54
|
+
getAccessTokenBySessionData(sessionData: SessionData, options?: GetAccessTokenOptions): Promise<string | null>;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/oauth-manager/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const assert_1 = require("assert");
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const SessionDataImpl_1 = require("../SessionDataImpl");
|
|
6
|
+
const createOAuthManager_1 = require("../factories/createOAuthManager");
|
|
7
|
+
const REDIS = 'redis://default:redispw@localhost:49153';
|
|
8
|
+
async function main() {
|
|
9
|
+
const oauthManager = (0, createOAuthManager_1.createOAuthManager)({
|
|
10
|
+
env: types_1.Env.DEV,
|
|
11
|
+
apiVersion: 'v20230109',
|
|
12
|
+
storage: 'redis',
|
|
13
|
+
redisURL: REDIS,
|
|
14
|
+
});
|
|
15
|
+
const clientId = process.env.CLIENT_ID;
|
|
16
|
+
(0, assert_1.ok)(clientId, 'clientId should be defined');
|
|
17
|
+
const clientSecret = process.env.CLIENT_SECRET;
|
|
18
|
+
(0, assert_1.ok)(clientSecret, 'clientSecret should be defined');
|
|
19
|
+
const scopes = ['companies:read', 'properties:download', 'lead_info:write'];
|
|
20
|
+
const sessionData = new SessionDataImpl_1.SessionDataImpl({
|
|
21
|
+
clientId,
|
|
22
|
+
clientSecret,
|
|
23
|
+
scopes,
|
|
24
|
+
});
|
|
25
|
+
const promises = [];
|
|
26
|
+
for (let i = 0; i < 10; i++) {
|
|
27
|
+
promises.push((async () => {
|
|
28
|
+
const token = await oauthManager.getAccessTokenBySessionData(sessionData);
|
|
29
|
+
console.log(token?.length);
|
|
30
|
+
})());
|
|
31
|
+
}
|
|
32
|
+
await Promise.all(promises);
|
|
33
|
+
}
|
|
34
|
+
main()
|
|
35
|
+
.then(() => {
|
|
36
|
+
process.exit(0);
|
|
37
|
+
})
|
|
38
|
+
.catch((e) => {
|
|
39
|
+
console.error(e);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/oauth-manager/playground/main.ts"],"names":[],"mappings":";;AAAA,mCAA4B;AAC5B,uCAAkC;AAClC,wDAAqD;AACrD,wEAAqE;AAErE,MAAM,KAAK,GAAG,yCAAyC,CAAC;AAExD,KAAK,UAAU,IAAI;IACjB,MAAM,YAAY,GAAG,IAAA,uCAAkB,EAAC;QACtC,GAAG,EAAE,WAAG,CAAC,GAAG;QACZ,UAAU,EAAE,WAAW;QACvB,OAAO,EAAE,OAAO;QAChB,QAAQ,EAAE,KAAK;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only getAll: ({ companyId }: {
|
|
4
|
+
companyId: string;
|
|
5
|
+
}) => Promise<import("axios").AxiosResponse<any>>;
|
|
6
|
+
readonly get: ({ channelAccountId }: {
|
|
7
|
+
channelAccountId: string;
|
|
8
|
+
}) => Promise<import("axios").AxiosResponse<any>>;
|
|
9
|
+
readonly getEstateHash: ({ estateId, channelAccountId, }: {
|
|
10
|
+
estateId: string;
|
|
11
|
+
channelAccountId: string;
|
|
12
|
+
}) => Promise<{
|
|
13
|
+
hash: string;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("../types");
|
|
4
|
+
function default_1(ctx) {
|
|
5
|
+
async function getAll({ companyId }) {
|
|
6
|
+
ctx.checkAuth(types_1.TokenType.API_TOKEN);
|
|
7
|
+
const endpoint = `/services/companies/${companyId}/channel-accounts`;
|
|
8
|
+
return ctx.httpClient.get(endpoint, {
|
|
9
|
+
params: {
|
|
10
|
+
includes: 'channel',
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
async function get({ channelAccountId }) {
|
|
15
|
+
ctx.checkAuth(types_1.TokenType.API_TOKEN);
|
|
16
|
+
const endpoint = `/services/channel-accounts/${channelAccountId}`;
|
|
17
|
+
return ctx.httpClient.get(endpoint, {
|
|
18
|
+
params: {
|
|
19
|
+
includes: 'channel',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async function getEstateHash({ estateId, channelAccountId, }) {
|
|
24
|
+
const endpoint = `services/estates/${estateId}/channel-accounts/${channelAccountId}/hash`;
|
|
25
|
+
const response = await ctx.httpClient.post(endpoint);
|
|
26
|
+
return response.data;
|
|
27
|
+
}
|
|
28
|
+
return { getAll, get, getEstateHash };
|
|
29
|
+
}
|
|
30
|
+
exports.default = default_1;
|
|
31
|
+
//# sourceMappingURL=channel_accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel_accounts.js","sourceRoot":"","sources":["../../src/resources/channel_accounts.ts"],"names":[],"mappings":";;AAAA,oCAAgD;AAEhD,mBAAyB,GAAc;IACrC,KAAK,UAAU,MAAM,CAAC,EAAE,SAAS,EAAyB;QACxD,GAAG,CAAC,SAAS,CAAC,iBAAS,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,QAAQ,GAAG,uBAAuB,SAAS,mBAAmB,CAAC;QAErE,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE;YAClC,MAAM,EAAE;gBACN,QAAQ,EAAE,SAAS;aACpB;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,UAAU,GAAG,CAAC,EAAE,gBAAgB,EAAgC;QACnE,GAAG,CAAC,SAAS,CAAC,iBAAS,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,QAAQ,GAAG,8BAA8B,gBAAgB,EAAE,CAAC;QAElE,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE;YAClC,MAAM,EAAE;gBACN,QAAQ,EAAE,SAAS;aACpB;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,UAAU,aAAa,CAAC,EAC3B,QAAQ,EACR,gBAAgB,GAIjB;QACC,MAAM,QAAQ,GAAG,oBAAoB,QAAQ,qBAAqB,gBAAgB,OAAO,CAAC;QAC1F,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrD,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,EAAW,CAAC;AACjD,CAAC;AApCD,4BAoCC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ClientCtx } from '../types';
|
|
2
|
+
interface ReferenceDetails {
|
|
3
|
+
reference_code: string;
|
|
4
|
+
estate_id: string;
|
|
5
|
+
channel_id: string;
|
|
6
|
+
channel_account_id: string;
|
|
7
|
+
company_id: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ChannelsResolveReferencesResult {
|
|
10
|
+
data: ReferenceDetails[];
|
|
11
|
+
}
|
|
12
|
+
export default function (ctx: ClientCtx): {
|
|
13
|
+
getPropertyIdFromReference: (channel: string, referenceId: string) => Promise<import("axios").AxiosResponse<any>>;
|
|
14
|
+
resolveReferences: (channel_id: string, reference_code: string, company_id?: string) => Promise<ChannelsResolveReferencesResult>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("../types");
|
|
4
|
+
function default_1(ctx) {
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use channels.resolveReferences()
|
|
7
|
+
*/
|
|
8
|
+
async function getPropertyIdFromReference(channel, referenceId) {
|
|
9
|
+
ctx.checkAuth(types_1.TokenType.API_TOKEN);
|
|
10
|
+
const endpoint = `/channels/${channel}/channel-references/${referenceId}`;
|
|
11
|
+
return ctx.httpClient.get(endpoint);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @param channel_id Channel ID, for example, `"immoweb"` or `"immovlan"` etc
|
|
15
|
+
* @param reference_code Reference
|
|
16
|
+
* @param company_id Company ID
|
|
17
|
+
*/
|
|
18
|
+
async function resolveReferences(channel_id, reference_code, company_id) {
|
|
19
|
+
ctx.checkAuth(types_1.TokenType.API_TOKEN);
|
|
20
|
+
const endpoint = `/services/channel-references`;
|
|
21
|
+
return ctx.httpClient.get(endpoint, {
|
|
22
|
+
params: {
|
|
23
|
+
channel_id,
|
|
24
|
+
reference_code,
|
|
25
|
+
company_id,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return { getPropertyIdFromReference, resolveReferences };
|
|
30
|
+
}
|
|
31
|
+
exports.default = default_1;
|
|
32
|
+
//# sourceMappingURL=channels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channels.js","sourceRoot":"","sources":["../../src/resources/channels.ts"],"names":[],"mappings":";;AAAA,oCAAgD;AAchD,mBAAyB,GAAc;IACrC;;OAEG;IACH,KAAK,UAAU,0BAA0B,CACvC,OAAe,EACf,WAAmB;QAEnB,GAAG,CAAC,SAAS,CAAC,iBAAS,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,QAAQ,GAAG,aAAa,OAAO,uBAAuB,WAAW,EAAE,CAAC;QAE1E,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,UAAU,iBAAiB,CAC9B,UAAkB,EAClB,cAAsB,EACtB,UAAmB;QAEnB,GAAG,CAAC,SAAS,CAAC,iBAAS,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,QAAQ,GAAG,8BAA8B,CAAC;QAEhD,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE;YAClC,MAAM,EAAE;gBACN,UAAU;gBACV,cAAc;gBACd,UAAU;aACX;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,CAAC;AAC3D,CAAC;AArCD,4BAqCC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("../types");
|
|
4
|
+
function default_1(ctx) {
|
|
5
|
+
function get(attributes) {
|
|
6
|
+
ctx.checkAuth(types_1.TokenType.API_TOKEN);
|
|
7
|
+
return ctx.httpClient.get(`/companies/${attributes.companyId}`, {
|
|
8
|
+
params: {
|
|
9
|
+
includes: attributes.includes?.join(','),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return { get };
|
|
14
|
+
}
|
|
15
|
+
exports.default = default_1;
|
|
16
|
+
//# sourceMappingURL=companies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"companies.js","sourceRoot":"","sources":["../../src/resources/companies.ts"],"names":[],"mappings":";;AAAA,oCAAgD;AAEhD,mBAAyB,GAAc;IACrC,SAAS,GAAG,CAAC,UAAsD;QACjE,GAAG,CAAC,SAAS,CAAC,iBAAS,CAAC,SAAS,CAAC,CAAC;QAEnC,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,cAAc,UAAU,CAAC,SAAS,EAAE,EAAE;YAC9D,MAAM,EAAE;gBACN,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC;aACzC;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,CAAC;AACjB,CAAC;AAZD,4BAYC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("../types");
|
|
4
|
+
function contact_preferences(ctx) {
|
|
5
|
+
function getAll(attributes) {
|
|
6
|
+
ctx.checkAuth(types_1.TokenType.API_TOKEN);
|
|
7
|
+
return ctx.httpClient.get(`/services/contacts/${attributes.contactId}/preferences`);
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
getAll,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.default = contact_preferences;
|
|
14
|
+
//# sourceMappingURL=contact_preferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contact_preferences.js","sourceRoot":"","sources":["../../src/resources/contact_preferences.ts"],"names":[],"mappings":";;AAAA,oCAAgD;AAEhD,SAAwB,mBAAmB,CAAC,GAAc;IACxD,SAAS,MAAM,CAAC,UAAiC;QAC/C,GAAG,CAAC,SAAS,CAAC,iBAAS,CAAC,SAAS,CAAC,CAAC;QACnC,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CACvB,sBAAsB,UAAU,CAAC,SAAS,cAAc,CACzD,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM;KACP,CAAC;AACJ,CAAC;AAXD,sCAWC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ClientCtx } from '../types';
|
|
2
|
+
export default function (ctx: ClientCtx): {
|
|
3
|
+
getOne: (attributes: {
|
|
4
|
+
contactId: string;
|
|
5
|
+
}) => Promise<import("axios").AxiosResponse<any>>;
|
|
6
|
+
getOneWithNegotiators: (attributes: {
|
|
7
|
+
contactId: string;
|
|
8
|
+
}) => Promise<import("axios").AxiosResponse<any>>;
|
|
9
|
+
getAll: (attributes: {
|
|
10
|
+
companyId: string;
|
|
11
|
+
page?: number;
|
|
12
|
+
limit?: number;
|
|
13
|
+
}) => Promise<import("axios").AxiosResponse<any>>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("../types");
|
|
4
|
+
function default_1(ctx) {
|
|
5
|
+
function getOne(attributes) {
|
|
6
|
+
ctx.checkAuth(types_1.TokenType.API_TOKEN);
|
|
7
|
+
return ctx.httpClient.get(`/services/contacts/${attributes.contactId}`);
|
|
8
|
+
}
|
|
9
|
+
function getOneWithNegotiators(attributes) {
|
|
10
|
+
ctx.checkAuth(types_1.TokenType.API_TOKEN);
|
|
11
|
+
return ctx.httpClient.get(`/services/contacts/${attributes.contactId}?includes=negotiators`);
|
|
12
|
+
}
|
|
13
|
+
function getAll(attributes) {
|
|
14
|
+
ctx.checkAuth(types_1.TokenType.API_TOKEN);
|
|
15
|
+
return ctx.httpClient.get(`/services/companies/${attributes.companyId}/contacts`, {
|
|
16
|
+
params: {
|
|
17
|
+
page: attributes.page ?? 1,
|
|
18
|
+
limit: attributes.limit ?? 10,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
getOne,
|
|
24
|
+
getOneWithNegotiators,
|
|
25
|
+
getAll,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.default = default_1;
|
|
29
|
+
//# sourceMappingURL=contacts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contacts.js","sourceRoot":"","sources":["../../src/resources/contacts.ts"],"names":[],"mappings":";;AAAA,oCAAgD;AAEhD,mBAAyB,GAAc;IACrC,SAAS,MAAM,CAAC,UAAiC;QAC/C,GAAG,CAAC,SAAS,CAAC,iBAAS,CAAC,SAAS,CAAC,CAAC;QACnC,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,sBAAsB,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,SAAS,qBAAqB,CAAC,UAAiC;QAC9D,GAAG,CAAC,SAAS,CAAC,iBAAS,CAAC,SAAS,CAAC,CAAC;QACnC,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CACvB,sBAAsB,UAAU,CAAC,SAAS,uBAAuB,CAClE,CAAC;IACJ,CAAC;IAED,SAAS,MAAM,CAAC,UAIf;QACC,GAAG,CAAC,SAAS,CAAC,iBAAS,CAAC,SAAS,CAAC,CAAC;QACnC,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CACvB,uBAAuB,UAAU,CAAC,SAAS,WAAW,EACtD;YACE,MAAM,EAAE;gBACN,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC;gBAC1B,KAAK,EAAE,UAAU,CAAC,KAAK,IAAI,EAAE;aAC9B;SACF,CACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM;QACN,qBAAqB;QACrB,MAAM;KACP,CAAC;AACJ,CAAC;AAnCD,4BAmCC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Property } from '../entities/property';
|
|
2
|
+
import { ClientCtx, EstateInclude, GetUnitsInput, PropertiesOutput, UnitsOutput } from '../types';
|
|
3
|
+
export default function (ctx: ClientCtx): {
|
|
4
|
+
getOne: (attributes: {
|
|
5
|
+
estateId: string;
|
|
6
|
+
companyId: string;
|
|
7
|
+
includes?: EstateInclude[];
|
|
8
|
+
}) => Promise<Property>;
|
|
9
|
+
getAll: (attributes: {
|
|
10
|
+
companyId: string;
|
|
11
|
+
page?: number;
|
|
12
|
+
limit?: number;
|
|
13
|
+
archived?: boolean;
|
|
14
|
+
}) => Promise<PropertiesOutput>;
|
|
15
|
+
getUnits: (projectId: string, { page, limit, includes }?: GetUnitsInput) => Promise<UnitsOutput>;
|
|
16
|
+
createPublication: (attributes: {
|
|
17
|
+
estateId: string;
|
|
18
|
+
channelAccountId: string;
|
|
19
|
+
config: Record<string, any>;
|
|
20
|
+
}) => Promise<import("axios").AxiosResponse<any>>;
|
|
21
|
+
updatePublication: (attributes: {
|
|
22
|
+
estateId: string;
|
|
23
|
+
channelAccountId: string;
|
|
24
|
+
config: Record<string, any>;
|
|
25
|
+
}) => Promise<import("axios").AxiosResponse<any>>;
|
|
26
|
+
unpublishPublication: (attributes: {
|
|
27
|
+
estateId: string;
|
|
28
|
+
channelAccountId: string;
|
|
29
|
+
}) => Promise<import("axios").AxiosResponse<any>>;
|
|
30
|
+
scheduleVisit: (estateId: string, attributes: {
|
|
31
|
+
first_name: string;
|
|
32
|
+
last_name: string;
|
|
33
|
+
email: string;
|
|
34
|
+
phone: string;
|
|
35
|
+
preferences?: {
|
|
36
|
+
locale: string;
|
|
37
|
+
};
|
|
38
|
+
}) => Promise<import("axios").AxiosResponse<any>>;
|
|
39
|
+
unstable_setPublicationUrl: ({ estateId, url, }: {
|
|
40
|
+
estateId: string;
|
|
41
|
+
url: string;
|
|
42
|
+
}) => Promise<import("axios").AxiosResponse<any>>;
|
|
43
|
+
};
|