@digipair/skill-smoobu 0.90.0 → 0.91.0-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/.swcrc ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "jsc": {
3
+ "target": "es2017",
4
+ "parser": {
5
+ "syntax": "typescript",
6
+ "decorators": true,
7
+ "dynamicImport": true
8
+ },
9
+ "transform": {
10
+ "decoratorMetadata": true,
11
+ "legacyDecorator": true
12
+ },
13
+ "keepClassNames": true,
14
+ "externalHelpers": true,
15
+ "loose": true
16
+ },
17
+ "module": {
18
+ "type": "es6"
19
+ },
20
+ "sourceMaps": true,
21
+ "exclude": [
22
+ "jest.config.ts",
23
+ ".*\\.spec.tsx?$",
24
+ ".*\\.test.tsx?$",
25
+ "./src/jest-setup.ts$",
26
+ "./**/jest-setup.ts$"
27
+ ]
28
+ }
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # mylib
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build mylib` to build the library.
@@ -0,0 +1,22 @@
1
+ import baseConfig from '../../eslint.config.mjs';
2
+
3
+ export default [
4
+ ...baseConfig,
5
+ {
6
+ files: ['**/*.json'],
7
+ rules: {
8
+ '@nx/dependency-checks': [
9
+ 'error',
10
+ {
11
+ ignoredFiles: [
12
+ '{projectRoot}/eslint.config.{js,cjs,mjs}',
13
+ '{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}',
14
+ ],
15
+ },
16
+ ],
17
+ },
18
+ languageOptions: {
19
+ parser: await import('jsonc-eslint-parser'),
20
+ },
21
+ },
22
+ ];
package/package.json CHANGED
@@ -1,12 +1,28 @@
1
1
  {
2
2
  "name": "@digipair/skill-smoobu",
3
- "version": "0.90.0",
3
+ "version": "0.91.0-0",
4
+ "type": "module",
5
+ "main": "dist/libs/skill-smoobu/index.cjs.js",
6
+ "module": "dist/libs/skill-smoobu/index.esm.js",
7
+ "types": "dist/libs/skill-smoobu/index.esm.d.ts",
8
+ "exports": {
9
+ "./package.json": "./libs/skill-smoobu/package.json",
10
+ ".": {
11
+ "development": "./dist/libs/skill-smoobu/src/index.ts",
12
+ "types": "./dist/libs/skill-smoobu/index.esm.d.ts",
13
+ "import": "./dist/libs/skill-smoobu/index.esm.js",
14
+ "default": "./dist/libs/skill-smoobu/index.cjs.js"
15
+ }
16
+ },
4
17
  "keywords": [
5
18
  "digipair",
6
- "service",
7
- "tool"
19
+ "tool",
20
+ "service"
8
21
  ],
9
- "dependencies": {},
10
- "main": "./index.cjs.js",
11
- "module": "./index.esm.js"
12
- }
22
+ "nx": {
23
+ "name": "skill-smoobu"
24
+ },
25
+ "dependencies": {
26
+ "@digipair/engine": "0.91.0-0"
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+ const { withNx } = require('@nx/rollup/with-nx');
2
+
3
+ module.exports = withNx(
4
+ {
5
+ main: 'libs/skill-smoobu/src/index.ts',
6
+ outputPath: 'dist/libs/skill-smoobu',
7
+ tsConfig: 'libs/skill-smoobu/tsconfig.lib.json',
8
+ compiler: 'swc',
9
+ format: ['esm', "cjs"],
10
+ assets: [
11
+ {
12
+ input: 'libs/skill-smoobu/',
13
+ glob: 'package.json',
14
+ output: '.'
15
+ },
16
+ {
17
+ input: 'libs/skill-smoobu/src/',
18
+ glob: '*.json',
19
+ output: '.'
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
25
+ // e.g.
26
+ // output: { sourcemap: true },
27
+ }
28
+ );
@@ -0,0 +1 @@
1
+ declare module 'handlebars/dist/handlebars.min.js';
@@ -0,0 +1,7 @@
1
+ import { skillSmoobu } from './skill-smoobu';
2
+
3
+ describe('skillSmoobu', () => {
4
+ it('should work', () => {
5
+ expect(skillSmoobu()).toEqual('skill-smoobu');
6
+ });
7
+ });
@@ -0,0 +1,147 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/no-unused-vars */
3
+ import { PinsSettings, executePinsList } from '@digipair/engine';
4
+
5
+ class SmoobuService {
6
+ private SMOOBU_API_KEY: string;
7
+ private API_ENDPOINT: string;
8
+
9
+ constructor(context: any, params: any) {
10
+ this.SMOOBU_API_KEY =
11
+ context.privates.SMOOBU_API_KEY ?? params?.SMOOBU_API_KEY ?? process.env['SMOOBU_API_KEY'];
12
+ this.API_ENDPOINT =
13
+ context.privates.SMOOBU_API_ENDPOINT ??
14
+ params?.SMOOBU_API_ENDPOINT ??
15
+ process.env['SMOOBU_API_ENDPOINT'] ??
16
+ 'https://login.smoobu.com/api';
17
+ }
18
+
19
+ private async call(url: string, method: string, data: any, headers: any, signal: AbortSignal) {
20
+ const response = await fetch(`${this.API_ENDPOINT}${url}`, {
21
+ signal,
22
+ method,
23
+ headers: {
24
+ 'Api-Key': this.SMOOBU_API_KEY,
25
+ ...headers,
26
+ },
27
+ body: data,
28
+ });
29
+ if (!response.ok) throw new Error('[SKILL-SMOOBU] REQUEST FAILED: ' + response.status);
30
+ return await response.json();
31
+ }
32
+
33
+ async getReservationWithId(
34
+ params: any,
35
+ _pinsSettingsList: PinsSettings[],
36
+ context: any,
37
+ ): Promise<any> {
38
+ const { reservationId } = params;
39
+ return await this.call(
40
+ `/reservations/${reservationId}`,
41
+ 'GET',
42
+ null,
43
+ {},
44
+ context.protected?.signal,
45
+ );
46
+ }
47
+
48
+ async getAllReservations(
49
+ params: any,
50
+ _pinsSettingsList: PinsSettings[],
51
+ context: any,
52
+ ): Promise<any> {
53
+ const {
54
+ created_from,
55
+ created_to,
56
+ from,
57
+ to,
58
+ modifiedFrom,
59
+ modifiedTo,
60
+ arrivalFrom,
61
+ arrivalTo,
62
+ departureFrom,
63
+ departureTo,
64
+ showCancellation,
65
+ excludeBlocked,
66
+ page,
67
+ pageSize,
68
+ apartmentId,
69
+ includeRelated,
70
+ includePriceElements,
71
+ } = params;
72
+ const queryParams = new URLSearchParams();
73
+
74
+ if (created_from) queryParams.append('created_from', created_from);
75
+ if (created_to) queryParams.append('created_to', created_to);
76
+ if (from) queryParams.append('from', from);
77
+ if (to) queryParams.append('to', to);
78
+ if (modifiedFrom) queryParams.append('modifiedFrom', modifiedFrom);
79
+ if (modifiedTo) queryParams.append('modifiedTo', modifiedTo);
80
+ if (arrivalFrom) queryParams.append('arrivalFrom', arrivalFrom);
81
+ if (arrivalTo) queryParams.append('arrivalTo', arrivalTo);
82
+ if (departureFrom) queryParams.append('departureFrom', departureFrom);
83
+ if (departureTo) queryParams.append('departureTo', departureTo);
84
+ if (showCancellation) queryParams.append('showCancellation', showCancellation);
85
+ if (excludeBlocked) queryParams.append('excludeBlocked', excludeBlocked);
86
+ if (page) queryParams.append('page', page);
87
+ if (pageSize) queryParams.append('pageSize', pageSize);
88
+ if (apartmentId) queryParams.append('apartmentId', apartmentId);
89
+ if (includeRelated) queryParams.append('includeRelated', includeRelated);
90
+ if (includePriceElements) queryParams.append('includePriceElements', includePriceElements);
91
+
92
+ return await this.call(
93
+ `/reservations?${queryParams.toString()}`,
94
+ 'GET',
95
+ null,
96
+ {},
97
+ context.protected?.signal,
98
+ );
99
+ }
100
+
101
+ async sendMessage(params: any, _pinsSettingsList: PinsSettings[], context: any): Promise<any> {
102
+ const { reservationId, message } = params;
103
+ return await this.call(
104
+ `/reservations/${reservationId}/messages/send-message-to-guest`,
105
+ 'POST',
106
+ JSON.stringify({
107
+ messageBody: message,
108
+ }),
109
+ {},
110
+ context.protected?.signal,
111
+ );
112
+ }
113
+
114
+ async event(params: any, _pinsSettingsList: PinsSettings[], context: any): Promise<any> {
115
+ const {
116
+ updateRates = [],
117
+ newReservation = [],
118
+ cancelReservation = [],
119
+ updateReservation = [],
120
+ } = params;
121
+ const actions = { updateRates, newReservation, cancelReservation, updateReservation };
122
+
123
+ return await executePinsList(
124
+ actions[
125
+ context.request.body.action as
126
+ | 'updateRates'
127
+ | 'newReservation'
128
+ | 'cancelReservation'
129
+ | 'updateReservation'
130
+ ],
131
+ context,
132
+ `${context.__PATH__}.${context.request.body.action}`,
133
+ );
134
+ }
135
+ }
136
+
137
+ export const event = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
138
+ new SmoobuService(context, params).event(params, pinsSettingsList, context);
139
+
140
+ export const getReservationWithId = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
141
+ new SmoobuService(context, params).getReservationWithId(params, pinsSettingsList, context);
142
+
143
+ export const getAllReservations = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
144
+ new SmoobuService(context, params).getAllReservations(params, pinsSettingsList, context);
145
+
146
+ export const sendMessage = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
147
+ new SmoobuService(context, params).sendMessage(params, pinsSettingsList, context);
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "../engine"
8
+ },
9
+ {
10
+ "path": "./tsconfig.lib.json"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
7
+ "emitDeclarationOnly": true,
8
+ "module": "esnext",
9
+ "moduleResolution": "node",
10
+ "forceConsistentCasingInFileNames": true,
11
+ "types": ["node"]
12
+ },
13
+ "include": ["src/**/*.ts"],
14
+ "references": [
15
+ {
16
+ "path": "../engine/tsconfig.lib.json"
17
+ }
18
+ ]
19
+ }
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
package/index.cjs.js DELETED
@@ -1,91 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var engine = require('@digipair/engine');
6
-
7
- function _extends() {
8
- _extends = Object.assign || function assign(target) {
9
- for(var i = 1; i < arguments.length; i++){
10
- var source = arguments[i];
11
- for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
12
- }
13
- return target;
14
- };
15
- return _extends.apply(this, arguments);
16
- }
17
-
18
- let SmoobuService = class SmoobuService {
19
- async call(url, method, data, headers, signal) {
20
- const response = await fetch(`${this.API_ENDPOINT}${url}`, {
21
- signal,
22
- method,
23
- headers: _extends({
24
- 'Api-Key': this.SMOOBU_API_KEY
25
- }, headers),
26
- body: data
27
- });
28
- if (!response.ok) throw new Error('[SKILL-SMOOBU] REQUEST FAILED: ' + response.status);
29
- return await response.json();
30
- }
31
- async getReservationWithId(params, _pinsSettingsList, context) {
32
- var _context_protected;
33
- const { reservationId } = params;
34
- return await this.call(`/reservations/${reservationId}`, 'GET', null, {}, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
35
- }
36
- async getAllReservations(params, _pinsSettingsList, context) {
37
- var _context_protected;
38
- const { created_from, created_to, from, to, modifiedFrom, modifiedTo, arrivalFrom, arrivalTo, departureFrom, departureTo, showCancellation, excludeBlocked, page, pageSize, apartmentId, includeRelated, includePriceElements } = params;
39
- const queryParams = new URLSearchParams();
40
- if (created_from) queryParams.append('created_from', created_from);
41
- if (created_to) queryParams.append('created_to', created_to);
42
- if (from) queryParams.append('from', from);
43
- if (to) queryParams.append('to', to);
44
- if (modifiedFrom) queryParams.append('modifiedFrom', modifiedFrom);
45
- if (modifiedTo) queryParams.append('modifiedTo', modifiedTo);
46
- if (arrivalFrom) queryParams.append('arrivalFrom', arrivalFrom);
47
- if (arrivalTo) queryParams.append('arrivalTo', arrivalTo);
48
- if (departureFrom) queryParams.append('departureFrom', departureFrom);
49
- if (departureTo) queryParams.append('departureTo', departureTo);
50
- if (showCancellation) queryParams.append('showCancellation', showCancellation);
51
- if (excludeBlocked) queryParams.append('excludeBlocked', excludeBlocked);
52
- if (page) queryParams.append('page', page);
53
- if (pageSize) queryParams.append('pageSize', pageSize);
54
- if (apartmentId) queryParams.append('apartmentId', apartmentId);
55
- if (includeRelated) queryParams.append('includeRelated', includeRelated);
56
- if (includePriceElements) queryParams.append('includePriceElements', includePriceElements);
57
- return await this.call(`/reservations?${queryParams.toString()}`, 'GET', null, {}, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
58
- }
59
- async sendMessage(params, _pinsSettingsList, context) {
60
- var _context_protected;
61
- const { reservationId, message } = params;
62
- return await this.call(`/reservations/${reservationId}/messages/send-message-to-guest`, 'POST', JSON.stringify({
63
- messageBody: message
64
- }), {}, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
65
- }
66
- async event(params, _pinsSettingsList, context) {
67
- const { updateRates = [], newReservation = [], cancelReservation = [], updateReservation = [] } = params;
68
- const actions = {
69
- updateRates,
70
- newReservation,
71
- cancelReservation,
72
- updateReservation
73
- };
74
- return await engine.executePinsList(actions[context.request.body.action], context, `${context.__PATH__}.${context.request.body.action}`);
75
- }
76
- constructor(context, params){
77
- var _context_privates_SMOOBU_API_KEY, _ref;
78
- this.SMOOBU_API_KEY = (_ref = (_context_privates_SMOOBU_API_KEY = context.privates.SMOOBU_API_KEY) != null ? _context_privates_SMOOBU_API_KEY : params == null ? void 0 : params.SMOOBU_API_KEY) != null ? _ref : process.env['SMOOBU_API_KEY'];
79
- var _context_privates_SMOOBU_API_ENDPOINT, _ref1, _ref2;
80
- this.API_ENDPOINT = (_ref2 = (_ref1 = (_context_privates_SMOOBU_API_ENDPOINT = context.privates.SMOOBU_API_ENDPOINT) != null ? _context_privates_SMOOBU_API_ENDPOINT : params == null ? void 0 : params.SMOOBU_API_ENDPOINT) != null ? _ref1 : process.env['SMOOBU_API_ENDPOINT']) != null ? _ref2 : 'https://login.smoobu.com/api';
81
- }
82
- };
83
- const event = (params, pinsSettingsList, context)=>new SmoobuService(context, params).event(params, pinsSettingsList, context);
84
- const getReservationWithId = (params, pinsSettingsList, context)=>new SmoobuService(context, params).getReservationWithId(params, pinsSettingsList, context);
85
- const getAllReservations = (params, pinsSettingsList, context)=>new SmoobuService(context, params).getAllReservations(params, pinsSettingsList, context);
86
- const sendMessage = (params, pinsSettingsList, context)=>new SmoobuService(context, params).sendMessage(params, pinsSettingsList, context);
87
-
88
- exports.event = event;
89
- exports.getAllReservations = getAllReservations;
90
- exports.getReservationWithId = getReservationWithId;
91
- exports.sendMessage = sendMessage;