@innobrain/onoffice-adapter-js 0.1.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.
@@ -0,0 +1,55 @@
1
+ export declare const OnOfficeAction: {
2
+ readonly Read: "urn:onoffice-de-ns:smart:2.5:smartml:action:read";
3
+ readonly Create: "urn:onoffice-de-ns:smart:2.5:smartml:action:create";
4
+ readonly Modify: "urn:onoffice-de-ns:smart:2.5:smartml:action:modify";
5
+ readonly Get: "urn:onoffice-de-ns:smart:2.5:smartml:action:get";
6
+ readonly Do: "urn:onoffice-de-ns:smart:2.5:smartml:action:do";
7
+ readonly Delete: "urn:onoffice-de-ns:smart:2.5:smartml:action:delete";
8
+ };
9
+ export type OnOfficeAction = (typeof OnOfficeAction)[keyof typeof OnOfficeAction];
10
+ export declare const OnOfficeResourceType: {
11
+ readonly Address: "address";
12
+ readonly Estate: "estate";
13
+ readonly EstatePictures: "estatepictures";
14
+ readonly Fields: "fields";
15
+ readonly Filters: "filters";
16
+ readonly File: "file";
17
+ readonly IdsFromRelation: "idsfromrelation";
18
+ readonly User: "user";
19
+ readonly Users: "users";
20
+ readonly UserPhoto: "userphoto";
21
+ readonly UnlockProvider: "unlockProvider";
22
+ readonly MarketplaceInvoiceRecipient: "getMarketplaceInvoiceRecipient";
23
+ readonly MarketplaceCancelAbo: "marketplaceCancelAbo";
24
+ readonly SubsequentPaymentLink: "subsequentPaymentLink";
25
+ readonly TransactionRefund: "transactionRefund";
26
+ readonly ExecuteMarketplaceWebhooks: "executeMarketplaceWebhooks";
27
+ readonly Regions: "regions";
28
+ readonly UploadFile: "uploadfile";
29
+ readonly FileRelation: "fileRelation";
30
+ readonly Impressum: "impressum";
31
+ readonly Activity: "agentslog";
32
+ readonly GetSearchCriteria: "searchcriterias";
33
+ readonly SearchCriteria: "searchcriteria";
34
+ readonly SearchCriteriaFields: "searchCriteriaFields";
35
+ readonly ActionTypes: "actionkindtypes";
36
+ readonly Relation: "relation";
37
+ readonly Search: "search";
38
+ readonly MultiselectKey: "multiselectkey";
39
+ readonly MacroResolve: "macroresolve";
40
+ readonly Log: "log";
41
+ readonly CheckUserRecordsRight: "checkuserrecordsright";
42
+ readonly GetLink: "getlink";
43
+ readonly RecordsLastSeen: "recordsLastSeen";
44
+ };
45
+ export type OnOfficeResourceType = (typeof OnOfficeResourceType)[keyof typeof OnOfficeResourceType];
46
+ export declare const ParameterKeys: {
47
+ readonly data: "data";
48
+ readonly listLimit: "listlimit";
49
+ readonly listOffset: "listoffset";
50
+ readonly filter: "filter";
51
+ readonly sortBy: "sortby";
52
+ readonly sortOrder: "sortorder";
53
+ readonly extendedClaim: "extendedclaim";
54
+ };
55
+ export declare const MAX_PAGE_SIZE = 500;
@@ -0,0 +1,53 @@
1
+ export const OnOfficeAction = {
2
+ Read: "urn:onoffice-de-ns:smart:2.5:smartml:action:read",
3
+ Create: "urn:onoffice-de-ns:smart:2.5:smartml:action:create",
4
+ Modify: "urn:onoffice-de-ns:smart:2.5:smartml:action:modify",
5
+ Get: "urn:onoffice-de-ns:smart:2.5:smartml:action:get",
6
+ Do: "urn:onoffice-de-ns:smart:2.5:smartml:action:do",
7
+ Delete: "urn:onoffice-de-ns:smart:2.5:smartml:action:delete",
8
+ };
9
+ export const OnOfficeResourceType = {
10
+ Address: "address",
11
+ Estate: "estate",
12
+ EstatePictures: "estatepictures",
13
+ Fields: "fields",
14
+ Filters: "filters",
15
+ File: "file",
16
+ IdsFromRelation: "idsfromrelation",
17
+ User: "user",
18
+ Users: "users",
19
+ UserPhoto: "userphoto",
20
+ UnlockProvider: "unlockProvider",
21
+ MarketplaceInvoiceRecipient: "getMarketplaceInvoiceRecipient",
22
+ MarketplaceCancelAbo: "marketplaceCancelAbo",
23
+ SubsequentPaymentLink: "subsequentPaymentLink",
24
+ TransactionRefund: "transactionRefund",
25
+ ExecuteMarketplaceWebhooks: "executeMarketplaceWebhooks",
26
+ Regions: "regions",
27
+ UploadFile: "uploadfile",
28
+ FileRelation: "fileRelation",
29
+ Impressum: "impressum",
30
+ Activity: "agentslog",
31
+ GetSearchCriteria: "searchcriterias",
32
+ SearchCriteria: "searchcriteria",
33
+ SearchCriteriaFields: "searchCriteriaFields",
34
+ ActionTypes: "actionkindtypes",
35
+ Relation: "relation",
36
+ Search: "search",
37
+ MultiselectKey: "multiselectkey",
38
+ MacroResolve: "macroresolve",
39
+ Log: "log",
40
+ CheckUserRecordsRight: "checkuserrecordsright",
41
+ GetLink: "getlink",
42
+ RecordsLastSeen: "recordsLastSeen",
43
+ };
44
+ export const ParameterKeys = {
45
+ data: "data",
46
+ listLimit: "listlimit",
47
+ listOffset: "listoffset",
48
+ filter: "filter",
49
+ sortBy: "sortby",
50
+ sortOrder: "sortorder",
51
+ extendedClaim: "extendedclaim",
52
+ };
53
+ export const MAX_PAGE_SIZE = 500;
@@ -0,0 +1,9 @@
1
+ export declare class OnOfficeError extends Error {
2
+ readonly code: number;
3
+ readonly isResponseError: boolean;
4
+ readonly response?: unknown;
5
+ constructor(message: string, code: number, options?: {
6
+ isResponseError?: boolean;
7
+ response?: unknown;
8
+ });
9
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,9 @@
1
+ export class OnOfficeError extends Error {
2
+ constructor(message, code, options) {
3
+ super(message);
4
+ this.name = "OnOfficeError";
5
+ this.code = code;
6
+ this.isResponseError = options?.isResponseError ?? false;
7
+ this.response = options?.response;
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ import { OnOfficeQueryBuilder, OnOfficeClient } from "./client";
2
+ export declare class FieldQueryBuilder<TRecord = unknown> extends OnOfficeQueryBuilder<TRecord> {
3
+ private modules;
4
+ constructor(client: OnOfficeClient);
5
+ withModules(modules: string[] | string): this;
6
+ get(): Promise<TRecord[]>;
7
+ first(): Promise<TRecord | null>;
8
+ }
package/dist/fields.js ADDED
@@ -0,0 +1,31 @@
1
+ import { OnOfficeAction, OnOfficeResourceType } from "./constants";
2
+ import { OnOfficeQueryBuilder } from "./client";
3
+ import { extractFirstRecord } from "./utils";
4
+ export class FieldQueryBuilder extends OnOfficeQueryBuilder {
5
+ constructor(client) {
6
+ super(client, OnOfficeResourceType.Fields);
7
+ this.modules = [];
8
+ }
9
+ withModules(modules) {
10
+ const next = Array.isArray(modules) ? modules : [modules];
11
+ this.modules = [...this.modules, ...next];
12
+ return this;
13
+ }
14
+ async get() {
15
+ return this.client.requestAll(OnOfficeAction.Get, this.resourceType, {
16
+ parameters: {
17
+ modules: this.modules,
18
+ ...this.customParameters,
19
+ },
20
+ });
21
+ }
22
+ async first() {
23
+ const response = await this.client.request(OnOfficeAction.Get, this.resourceType, {
24
+ parameters: {
25
+ modules: this.modules,
26
+ ...this.customParameters,
27
+ },
28
+ });
29
+ return extractFirstRecord(response);
30
+ }
31
+ }
@@ -0,0 +1,14 @@
1
+ import { OnOfficeClient } from "./client";
2
+ export declare class FileUploadQueryBuilder {
3
+ private readonly client;
4
+ private uploadBlockSize;
5
+ private customParameters;
6
+ constructor(client: OnOfficeClient);
7
+ uploadInBlocks(blockSize?: number): this;
8
+ parameter(key: string, value: unknown): this;
9
+ parameters(parameters: Record<string, unknown>): this;
10
+ save(fileContent: string): Promise<string>;
11
+ link(tmpUploadId: string, data?: Record<string, unknown>): Promise<unknown>;
12
+ saveAndLink(fileContent: string, data?: Record<string, unknown>): Promise<unknown>;
13
+ private splitFileContent;
14
+ }
package/dist/files.js ADDED
@@ -0,0 +1,73 @@
1
+ import { OnOfficeAction, OnOfficeResourceType, ParameterKeys } from "./constants";
2
+ import { extractFirstRecord } from "./utils";
3
+ export class FileUploadQueryBuilder {
4
+ constructor(client) {
5
+ this.client = client;
6
+ this.uploadBlockSize = 0;
7
+ this.customParameters = {};
8
+ }
9
+ uploadInBlocks(blockSize = 20480) {
10
+ this.uploadBlockSize = Math.max(1, blockSize);
11
+ return this;
12
+ }
13
+ parameter(key, value) {
14
+ this.customParameters[key] = value;
15
+ return this;
16
+ }
17
+ parameters(parameters) {
18
+ this.customParameters = {
19
+ ...this.customParameters,
20
+ ...parameters,
21
+ };
22
+ return this;
23
+ }
24
+ async save(fileContent) {
25
+ const blocks = this.splitFileContent(fileContent);
26
+ let tmpUploadId = "";
27
+ for (const block of blocks) {
28
+ const parameters = {
29
+ [ParameterKeys.data]: block,
30
+ ...this.customParameters,
31
+ };
32
+ if (tmpUploadId) {
33
+ parameters.tmpUploadId = tmpUploadId;
34
+ }
35
+ const response = await this.client.request(OnOfficeAction.Do, OnOfficeResourceType.UploadFile, {
36
+ parameters,
37
+ });
38
+ const record = response.response?.results?.[0]?.data?.records?.[0];
39
+ tmpUploadId = record?.elements?.tmpUploadId ?? tmpUploadId;
40
+ }
41
+ if (!tmpUploadId) {
42
+ throw new Error("Upload did not return tmpUploadId.");
43
+ }
44
+ return tmpUploadId;
45
+ }
46
+ async link(tmpUploadId, data = {}) {
47
+ const response = await this.client.request(OnOfficeAction.Do, OnOfficeResourceType.UploadFile, {
48
+ parameters: {
49
+ ...data,
50
+ tmpUploadId,
51
+ ...this.customParameters,
52
+ },
53
+ });
54
+ return extractFirstRecord(response);
55
+ }
56
+ async saveAndLink(fileContent, data = {}) {
57
+ const tmpUploadId = await this.save(fileContent);
58
+ return this.link(tmpUploadId, data);
59
+ }
60
+ splitFileContent(fileContent) {
61
+ if (!fileContent) {
62
+ return [fileContent];
63
+ }
64
+ if (this.uploadBlockSize <= 0) {
65
+ return [fileContent];
66
+ }
67
+ const chunks = [];
68
+ for (let index = 0; index < fileContent.length; index += this.uploadBlockSize) {
69
+ chunks.push(fileContent.slice(index, index + this.uploadBlockSize));
70
+ }
71
+ return chunks;
72
+ }
73
+ }
package/dist/hmac.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const createHmacSignature: (message: string, secret: string) => Promise<string>;
package/dist/hmac.js ADDED
@@ -0,0 +1,27 @@
1
+ const base64FromArrayBuffer = (buffer) => {
2
+ const bytes = new Uint8Array(buffer);
3
+ if (typeof btoa === "function") {
4
+ let binary = "";
5
+ bytes.forEach((byte) => {
6
+ binary += String.fromCharCode(byte);
7
+ });
8
+ return btoa(binary);
9
+ }
10
+ if (typeof Buffer !== "undefined") {
11
+ return Buffer.from(bytes).toString("base64");
12
+ }
13
+ throw new Error("No base64 encoder available");
14
+ };
15
+ export const createHmacSignature = async (message, secret) => {
16
+ if (globalThis.crypto?.subtle) {
17
+ const encoder = new TextEncoder();
18
+ const key = await globalThis.crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
19
+ const signature = await globalThis.crypto.subtle.sign("HMAC", key, encoder.encode(message));
20
+ return base64FromArrayBuffer(signature);
21
+ }
22
+ const nodeCrypto = await import("crypto").catch(() => null);
23
+ if (nodeCrypto?.createHmac) {
24
+ return nodeCrypto.createHmac("sha256", secret).update(message).digest("base64");
25
+ }
26
+ throw new Error("No crypto implementation available for HMAC");
27
+ };
@@ -0,0 +1,14 @@
1
+ export { MAX_PAGE_SIZE, OnOfficeAction, OnOfficeResourceType, ParameterKeys } from "./constants";
2
+ export { OnOfficeClient, OnOfficeQueryBuilder } from "./client";
3
+ export { ActivityQueryBuilder } from "./activity";
4
+ export { FieldQueryBuilder } from "./fields";
5
+ export { FileUploadQueryBuilder } from "./files";
6
+ export { SearchCriteriaFieldQueryBuilder, SearchCriteriaQueryBuilder, SearchCriteriaSearchQueryBuilder, } from "./search-criteria";
7
+ export { ActionQueryBuilder, ImprintQueryBuilder, RegionQueryBuilder, UserQueryBuilder, } from "./settings";
8
+ export { OnOfficeError } from "./errors";
9
+ export { createHmacSignature } from "./hmac";
10
+ export { compactParameters, extractRecords, extractFirstRecord } from "./utils";
11
+ export { ActivityRepository, AddressRepository, EstateRepository, FieldRepository, FileRepository, MarketplaceRepository, OnOfficeRepository, RawRepository, SearchCriteriaRepository, SettingRepository, createRepositories, } from "./repositories";
12
+ export type { Repositories } from "./repositories";
13
+ export type { AddressFileOptions, EstateFileOptions, MarketplaceCancelSubscriptionParams, MarketplaceExecuteWebhooksParams, MarketplaceInvoiceRecipientParams, MarketplaceRefundTransactionParams, MarketplaceSubsequentPaymentParams, MarketplaceUnlockProviderParams, MarketplaceWebhookModule, } from "./repositories";
14
+ export type { DebugRequestInfo, DebugResponseInfo, Fetcher, FilterOperator, OnOfficeApiResponse, OnOfficeClientConfig, OnOfficeRequestOptions, PaginationOptions, RetryOptions, } from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { MAX_PAGE_SIZE, OnOfficeAction, OnOfficeResourceType, ParameterKeys } from "./constants";
2
+ export { OnOfficeClient, OnOfficeQueryBuilder } from "./client";
3
+ export { ActivityQueryBuilder } from "./activity";
4
+ export { FieldQueryBuilder } from "./fields";
5
+ export { FileUploadQueryBuilder } from "./files";
6
+ export { SearchCriteriaFieldQueryBuilder, SearchCriteriaQueryBuilder, SearchCriteriaSearchQueryBuilder, } from "./search-criteria";
7
+ export { ActionQueryBuilder, ImprintQueryBuilder, RegionQueryBuilder, UserQueryBuilder, } from "./settings";
8
+ export { OnOfficeError } from "./errors";
9
+ export { createHmacSignature } from "./hmac";
10
+ export { compactParameters, extractRecords, extractFirstRecord } from "./utils";
11
+ export { ActivityRepository, AddressRepository, EstateRepository, FieldRepository, FileRepository, MarketplaceRepository, OnOfficeRepository, RawRepository, SearchCriteriaRepository, SettingRepository, createRepositories, } from "./repositories";
@@ -0,0 +1,120 @@
1
+ import { OnOfficeQueryBuilder, OnOfficeClient } from "./client";
2
+ import { OnOfficeResourceType } from "./constants";
3
+ import { ActivityQueryBuilder } from "./activity";
4
+ import { FieldQueryBuilder } from "./fields";
5
+ import { FileUploadQueryBuilder } from "./files";
6
+ import { SearchCriteriaFieldQueryBuilder, SearchCriteriaQueryBuilder, SearchCriteriaSearchQueryBuilder } from "./search-criteria";
7
+ import { ActionQueryBuilder, ImprintQueryBuilder, RegionQueryBuilder, UserQueryBuilder } from "./settings";
8
+ export declare class OnOfficeRepository {
9
+ protected readonly client: OnOfficeClient;
10
+ protected readonly resourceType?: OnOfficeResourceType | undefined;
11
+ constructor(client: OnOfficeClient, resourceType?: OnOfficeResourceType | undefined);
12
+ query<TRecord = unknown>(): OnOfficeQueryBuilder<TRecord>;
13
+ }
14
+ export declare class RawRepository {
15
+ protected readonly client: OnOfficeClient;
16
+ constructor(client: OnOfficeClient);
17
+ query<TRecord = unknown>(resourceType: string): OnOfficeQueryBuilder<TRecord>;
18
+ request(actionId: Parameters<OnOfficeClient["request"]>[0], resourceType: string, options?: Parameters<OnOfficeClient["request"]>[2]): Promise<import("./types").OnOfficeApiResponse<unknown>>;
19
+ requestAll(actionId: Parameters<OnOfficeClient["requestAll"]>[0], resourceType: string, options: Parameters<OnOfficeClient["requestAll"]>[2], pagination?: Parameters<OnOfficeClient["requestAll"]>[3]): Promise<unknown[]>;
20
+ }
21
+ export type MarketplaceWebhookModule = "estate" | "address" | "task" | "calendar";
22
+ export interface MarketplaceUnlockProviderParams {
23
+ parameterCacheId: string[] | string;
24
+ isRegularCustomer?: boolean;
25
+ extendedClaim?: string;
26
+ }
27
+ export interface MarketplaceInvoiceRecipientParams {
28
+ transactionId: number | string;
29
+ userId: number | string;
30
+ extendedClaim?: string;
31
+ }
32
+ export interface MarketplaceCancelSubscriptionParams {
33
+ aboId: string | number;
34
+ cancelationDate?: string;
35
+ extendedClaim?: string;
36
+ }
37
+ export interface MarketplaceSubsequentPaymentParams {
38
+ transactionId: number | string;
39
+ priceNet: string;
40
+ description: string;
41
+ sendMailToCustomer?: boolean;
42
+ }
43
+ export interface MarketplaceRefundTransactionParams {
44
+ transactionId: number | string;
45
+ }
46
+ export interface MarketplaceExecuteWebhooksParams {
47
+ module: MarketplaceWebhookModule;
48
+ extendedClaim?: string;
49
+ }
50
+ export declare class EstateRepository extends OnOfficeRepository {
51
+ constructor(client: OnOfficeClient);
52
+ }
53
+ export declare class AddressRepository extends OnOfficeRepository {
54
+ constructor(client: OnOfficeClient);
55
+ }
56
+ export declare class ActivityRepository extends OnOfficeRepository {
57
+ constructor(client: OnOfficeClient);
58
+ query<TRecord = unknown>(): ActivityQueryBuilder<TRecord>;
59
+ }
60
+ export declare class FieldRepository extends OnOfficeRepository {
61
+ constructor(client: OnOfficeClient);
62
+ query<TRecord = unknown>(): FieldQueryBuilder<TRecord>;
63
+ }
64
+ export declare class SearchCriteriaRepository extends OnOfficeRepository {
65
+ constructor(client: OnOfficeClient);
66
+ query<TRecord = unknown>(): SearchCriteriaQueryBuilder<TRecord>;
67
+ fields<TRecord = unknown>(): SearchCriteriaFieldQueryBuilder<TRecord>;
68
+ search<TRecord = unknown>(): SearchCriteriaSearchQueryBuilder<TRecord>;
69
+ records<TRecord = unknown>(): OnOfficeQueryBuilder<TRecord>;
70
+ }
71
+ export interface AddressFileOptions {
72
+ fileId?: number;
73
+ listLimit?: number;
74
+ listOffset?: number;
75
+ }
76
+ export interface EstateFileOptions {
77
+ fileId?: number;
78
+ documentAttribute?: string;
79
+ includeImageUrl?: "small" | "medium" | "original";
80
+ showIsPublishedOnHomepage?: boolean;
81
+ showPublicationStatus?: boolean;
82
+ listLimit?: number;
83
+ listOffset?: number;
84
+ }
85
+ export declare class FileRepository extends OnOfficeRepository {
86
+ constructor(client: OnOfficeClient);
87
+ upload(): FileUploadQueryBuilder;
88
+ addressFiles<TRecord = unknown>(addressId: number, options?: AddressFileOptions): Promise<TRecord[]>;
89
+ estateFiles<TRecord = unknown>(estateId: number, options?: EstateFileOptions): Promise<TRecord[]>;
90
+ private fetchFiles;
91
+ }
92
+ export declare class MarketplaceRepository {
93
+ private readonly client;
94
+ constructor(client: OnOfficeClient);
95
+ unlockProvider<TRecord = unknown>(params: MarketplaceUnlockProviderParams): Promise<TRecord[]>;
96
+ invoiceRecipient<TRecord = unknown>(params: MarketplaceInvoiceRecipientParams): Promise<TRecord[]>;
97
+ cancelSubscription<TRecord = unknown>(params: MarketplaceCancelSubscriptionParams): Promise<TRecord[]>;
98
+ generateSubsequentPaymentLink<TRecord = unknown>(params: MarketplaceSubsequentPaymentParams): Promise<TRecord[]>;
99
+ refundTransaction<TRecord = unknown>(params: MarketplaceRefundTransactionParams): Promise<TRecord[]>;
100
+ executeWebhooks<TRecord = unknown>(recordId: number | string, params: MarketplaceExecuteWebhooksParams): Promise<TRecord[]>;
101
+ }
102
+ export declare class SettingRepository extends OnOfficeRepository {
103
+ constructor(client: OnOfficeClient);
104
+ users<TRecord = unknown>(): UserQueryBuilder<TRecord>;
105
+ regions<TRecord = unknown>(): RegionQueryBuilder<TRecord>;
106
+ imprint<TRecord = unknown>(): ImprintQueryBuilder<TRecord>;
107
+ actions<TRecord = unknown>(): ActionQueryBuilder<TRecord>;
108
+ }
109
+ export interface Repositories {
110
+ raw: RawRepository;
111
+ estate: EstateRepository;
112
+ address: AddressRepository;
113
+ activity: ActivityRepository;
114
+ fields: FieldRepository;
115
+ searchCriteria: SearchCriteriaRepository;
116
+ file: FileRepository;
117
+ marketplace: MarketplaceRepository;
118
+ settings: SettingRepository;
119
+ }
120
+ export declare function createRepositories(client: OnOfficeClient): Repositories;
@@ -0,0 +1,211 @@
1
+ import { OnOfficeAction, OnOfficeResourceType, ParameterKeys } from "./constants";
2
+ import { ActivityQueryBuilder } from "./activity";
3
+ import { FieldQueryBuilder } from "./fields";
4
+ import { FileUploadQueryBuilder } from "./files";
5
+ import { SearchCriteriaFieldQueryBuilder, SearchCriteriaQueryBuilder, SearchCriteriaSearchQueryBuilder, } from "./search-criteria";
6
+ import { ActionQueryBuilder, ImprintQueryBuilder, RegionQueryBuilder, UserQueryBuilder, } from "./settings";
7
+ import { compactParameters, extractRecords } from "./utils";
8
+ export class OnOfficeRepository {
9
+ constructor(client, resourceType) {
10
+ this.client = client;
11
+ this.resourceType = resourceType;
12
+ }
13
+ query() {
14
+ if (!this.resourceType) {
15
+ throw new Error("Repository resource type is not configured.");
16
+ }
17
+ return this.client.resource(this.resourceType);
18
+ }
19
+ }
20
+ export class RawRepository {
21
+ constructor(client) {
22
+ this.client = client;
23
+ }
24
+ query(resourceType) {
25
+ return this.client.resource(resourceType);
26
+ }
27
+ request(actionId, resourceType, options) {
28
+ return this.client.request(actionId, resourceType, options);
29
+ }
30
+ requestAll(actionId, resourceType, options, pagination) {
31
+ return this.client.requestAll(actionId, resourceType, options, pagination);
32
+ }
33
+ }
34
+ export class EstateRepository extends OnOfficeRepository {
35
+ constructor(client) {
36
+ super(client, OnOfficeResourceType.Estate);
37
+ }
38
+ }
39
+ export class AddressRepository extends OnOfficeRepository {
40
+ constructor(client) {
41
+ super(client, OnOfficeResourceType.Address);
42
+ }
43
+ }
44
+ export class ActivityRepository extends OnOfficeRepository {
45
+ constructor(client) {
46
+ super(client, OnOfficeResourceType.Activity);
47
+ }
48
+ query() {
49
+ return new ActivityQueryBuilder(this.client);
50
+ }
51
+ }
52
+ export class FieldRepository extends OnOfficeRepository {
53
+ constructor(client) {
54
+ super(client, OnOfficeResourceType.Fields);
55
+ }
56
+ query() {
57
+ return new FieldQueryBuilder(this.client);
58
+ }
59
+ }
60
+ export class SearchCriteriaRepository extends OnOfficeRepository {
61
+ constructor(client) {
62
+ super(client);
63
+ }
64
+ query() {
65
+ return new SearchCriteriaQueryBuilder(this.client);
66
+ }
67
+ fields() {
68
+ return new SearchCriteriaFieldQueryBuilder(this.client);
69
+ }
70
+ search() {
71
+ return new SearchCriteriaSearchQueryBuilder(this.client);
72
+ }
73
+ records() {
74
+ return this.client.resource(OnOfficeResourceType.SearchCriteria);
75
+ }
76
+ }
77
+ export class FileRepository extends OnOfficeRepository {
78
+ constructor(client) {
79
+ super(client, OnOfficeResourceType.File);
80
+ }
81
+ upload() {
82
+ return new FileUploadQueryBuilder(this.client);
83
+ }
84
+ addressFiles(addressId, options = {}) {
85
+ return this.fetchFiles(OnOfficeResourceType.Address, {
86
+ addressid: addressId,
87
+ fileid: options.fileId,
88
+ }, {
89
+ listLimit: options.listLimit,
90
+ listOffset: options.listOffset,
91
+ });
92
+ }
93
+ estateFiles(estateId, options = {}) {
94
+ return this.fetchFiles(OnOfficeResourceType.Estate, {
95
+ estateid: estateId,
96
+ fileid: options.fileId,
97
+ documentAttribute: options.documentAttribute,
98
+ includeImageUrl: options.includeImageUrl,
99
+ showispublishedonhomepage: options.showIsPublishedOnHomepage,
100
+ showpublicationstatus: options.showPublicationStatus,
101
+ }, {
102
+ listLimit: options.listLimit,
103
+ listOffset: options.listOffset,
104
+ });
105
+ }
106
+ fetchFiles(resourceId, options, paginationOptions = {}) {
107
+ const parameters = compactParameters(options);
108
+ return this.client.requestAll(OnOfficeAction.Get, OnOfficeResourceType.File, {
109
+ resourceId,
110
+ parameters,
111
+ }, {
112
+ pageSize: paginationOptions.listLimit,
113
+ offset: paginationOptions.listOffset,
114
+ limit: paginationOptions.listLimit,
115
+ });
116
+ }
117
+ }
118
+ export class MarketplaceRepository {
119
+ constructor(client) {
120
+ this.client = client;
121
+ }
122
+ async unlockProvider(params) {
123
+ const response = await this.client.request(OnOfficeAction.Do, OnOfficeResourceType.UnlockProvider, {
124
+ parameters: compactParameters({
125
+ parameterCacheId: params.parameterCacheId,
126
+ isRegularCustomer: params.isRegularCustomer,
127
+ [ParameterKeys.extendedClaim]: params.extendedClaim,
128
+ }),
129
+ });
130
+ return extractRecords(response);
131
+ }
132
+ async invoiceRecipient(params) {
133
+ const response = await this.client.request(OnOfficeAction.Get, OnOfficeResourceType.MarketplaceInvoiceRecipient, {
134
+ parameters: compactParameters({
135
+ transactionid: params.transactionId,
136
+ userid: params.userId,
137
+ [ParameterKeys.extendedClaim]: params.extendedClaim,
138
+ }),
139
+ });
140
+ return extractRecords(response);
141
+ }
142
+ async cancelSubscription(params) {
143
+ const response = await this.client.request(OnOfficeAction.Do, OnOfficeResourceType.MarketplaceCancelAbo, {
144
+ parameters: compactParameters({
145
+ aboid: params.aboId,
146
+ cancelationDate: params.cancelationDate,
147
+ [ParameterKeys.extendedClaim]: params.extendedClaim,
148
+ }),
149
+ });
150
+ return extractRecords(response);
151
+ }
152
+ async generateSubsequentPaymentLink(params) {
153
+ const response = await this.client.request(OnOfficeAction.Do, OnOfficeResourceType.SubsequentPaymentLink, {
154
+ parameters: compactParameters({
155
+ transactionid: params.transactionId,
156
+ priceNet: params.priceNet,
157
+ description: params.description,
158
+ sendMailToCustomer: params.sendMailToCustomer,
159
+ }),
160
+ });
161
+ return extractRecords(response);
162
+ }
163
+ async refundTransaction(params) {
164
+ const response = await this.client.request(OnOfficeAction.Do, OnOfficeResourceType.TransactionRefund, {
165
+ parameters: compactParameters({
166
+ transactionid: params.transactionId,
167
+ }),
168
+ });
169
+ return extractRecords(response);
170
+ }
171
+ async executeWebhooks(recordId, params) {
172
+ const response = await this.client.request(OnOfficeAction.Do, OnOfficeResourceType.ExecuteMarketplaceWebhooks, {
173
+ resourceId: recordId,
174
+ parameters: compactParameters({
175
+ module: params.module,
176
+ [ParameterKeys.extendedClaim]: params.extendedClaim,
177
+ }),
178
+ });
179
+ return extractRecords(response);
180
+ }
181
+ }
182
+ export class SettingRepository extends OnOfficeRepository {
183
+ constructor(client) {
184
+ super(client);
185
+ }
186
+ users() {
187
+ return new UserQueryBuilder(this.client);
188
+ }
189
+ regions() {
190
+ return new RegionQueryBuilder(this.client);
191
+ }
192
+ imprint() {
193
+ return new ImprintQueryBuilder(this.client);
194
+ }
195
+ actions() {
196
+ return new ActionQueryBuilder(this.client);
197
+ }
198
+ }
199
+ export function createRepositories(client) {
200
+ return {
201
+ raw: new RawRepository(client),
202
+ estate: new EstateRepository(client),
203
+ address: new AddressRepository(client),
204
+ activity: new ActivityRepository(client),
205
+ fields: new FieldRepository(client),
206
+ searchCriteria: new SearchCriteriaRepository(client),
207
+ file: new FileRepository(client),
208
+ marketplace: new MarketplaceRepository(client),
209
+ settings: new SettingRepository(client),
210
+ };
211
+ }