@twotaps/site-utils-base 0.0.1

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/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # site-utils
2
+
3
+ The site-utils package contains utility code and components for building public-facing websites using Two Taps 2.0. It is available via npm at https://www.npmjs.com/package/@twotaps/site-utils for internal website use or for customers/partners.
4
+
5
+ ## Publish
6
+ ---
7
+ To publish the site-utils package on npm, you need an npm account. If you don't have one, create an account at https://www.npmjs.com/signup.
8
+
9
+ You also need permission from the Two Taps 2.0 admin to publish the site-utils package. Contact the Two Taps 2.0 admin to obtain the necessary permissions.
10
+
11
+ Once you have the required permissions, run the following command:
12
+
13
+ ```
14
+ yarn publish
15
+ ```
16
+ Provide the new version, npm username, email, and password.
17
+
18
+ Since site-utils is currently being used internally by the snap-fitness repository https://github.com/ltnetwork/snap-fitness-nextjs, that project needs to be updated to ensure the latest changes are available.
19
+
20
+ In that repository, in `package.json` file update to the latest version:
21
+ ```
22
+ "@twotaps/site-utils": "^0.1.xx",
23
+ ```
24
+ Still in that project, update the project dependencies:
25
+ ```
26
+ yarn install
27
+ ```
@@ -0,0 +1,14 @@
1
+ import type { CommandModule } from 'yargs';
2
+ export declare class GenerateSDL implements CommandModule {
3
+ command: string;
4
+ describe: string;
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ handler(args: {
9
+ [argName: string]: unknown;
10
+ _: (string | number)[];
11
+ $0: string;
12
+ }): Promise<void>;
13
+ }
14
+ export default GenerateSDL;
@@ -0,0 +1,35 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import axios from 'axios';
3
+ import * as fs from 'fs';
4
+ import * as path from 'path';
5
+ import yaml from 'yml';
6
+ export class GenerateSDL {
7
+ constructor() {
8
+ this.command = 'generate:sdl';
9
+ this.describe = 'Get schema from API';
10
+ }
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ // eslint-disable-next-line class-methods-use-this
15
+ async handler(args) {
16
+ try {
17
+ const configPath = path.resolve(process.cwd(), 'config.yml');
18
+ const configContent = fs.readFileSync(configPath, {
19
+ encoding: 'utf-8',
20
+ });
21
+ const config = yaml.parse(configContent);
22
+ const response = await axios.get(config.SchemaBuilderURI);
23
+ fs.writeFile('schema.gql', response.data, (err) => {
24
+ if (err)
25
+ throw err;
26
+ });
27
+ }
28
+ catch (err) {
29
+ console.error('Unable to retrieve schema: ', err.message);
30
+ process.exit(1); // Exit with error code 1 so that codegen is not executed
31
+ }
32
+ }
33
+ }
34
+ export default GenerateSDL;
35
+ //# sourceMappingURL=generate-sdl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-sdl.js","sourceRoot":"","sources":["../../src/cli/generate-sdl.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,IAAI,MAAM,KAAK,CAAC;AAQvB,MAAM,OAAO,WAAW;IAAxB;QACE,YAAO,GAAG,cAAc,CAAC;QAEzB,aAAQ,GAAG,qBAAqB,CAAC;IAsBnC,CAAC;IApBC;;OAEG;IACH,kDAAkD;IAClD,KAAK,CAAC,OAAO,CAAC,IAAwE;QACpF,IAAI;YACF,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;YAC7D,MAAM,aAAa,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE;gBAChD,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAC;YACH,MAAM,MAAM,GAAiB,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YACvD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;YAC1D,EAAE,CAAC,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE;gBAChD,IAAI,GAAG;oBAAE,MAAM,GAAG,CAAC;YACrB,CAAC,CAAC,CAAC;SACJ;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;YAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,yDAAyD;SAC3E;IACH,CAAC;CACF;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './page/index.js';
2
+ export * from './util.js';
3
+ export * from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './page/index.js';
2
+ export * from './util.js';
3
+ export * from './types.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './page.dto.js';
2
+ export * from './page.service.js';
@@ -0,0 +1,3 @@
1
+ export * from './page.dto.js';
2
+ export * from './page.service.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/page/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,64 @@
1
+ export declare class AssetDto {
2
+ id: number;
3
+ url: string;
4
+ altText: string;
5
+ accessLevel: number;
6
+ }
7
+ export declare class SiteDto {
8
+ id?: number;
9
+ customScriptHead: string;
10
+ customScriptBody: string;
11
+ }
12
+ export declare class Breadcrumb {
13
+ urlPath: string;
14
+ name: string;
15
+ }
16
+ export declare class PageDto {
17
+ id: number;
18
+ urlSegment: string;
19
+ name: string;
20
+ lang: string;
21
+ brandId: number;
22
+ properties: {};
23
+ allowCrawling: boolean;
24
+ site: SiteDto;
25
+ sitePath?: string;
26
+ metaTitle: string;
27
+ metaDescription: string;
28
+ ttschema: TTSchemaCustomDto[];
29
+ breadcrumbs: Breadcrumb[];
30
+ }
31
+ export declare class PageRevisionDto {
32
+ id: number;
33
+ schema: any;
34
+ }
35
+ export declare class PageRevisionSchemaDto {
36
+ id: number;
37
+ sortOrder: number;
38
+ properties: TTSchemaProperties[] | null;
39
+ ttschema: TTSchemaDto | null;
40
+ }
41
+ export declare class PageRevisionSchemaPropertyDto {
42
+ fieldId: number;
43
+ name: string;
44
+ value: string[];
45
+ }
46
+ export declare class TTSchemaDto {
47
+ id?: number;
48
+ titleSingular?: string;
49
+ titlePlural?: string;
50
+ properties: TTSchemaProperties[];
51
+ }
52
+ export declare class TTSchemaProperties {
53
+ fieldId: number;
54
+ name: string;
55
+ value: string[];
56
+ }
57
+ export declare class TTSchemaCustomDto extends TTSchemaDto {
58
+ sortOrder: number;
59
+ name: string;
60
+ anchorId?: string;
61
+ anchorOnly: boolean;
62
+ campaign?: boolean;
63
+ label?: string;
64
+ }
@@ -0,0 +1,21 @@
1
+ export class AssetDto {
2
+ }
3
+ export class SiteDto {
4
+ }
5
+ export class Breadcrumb {
6
+ }
7
+ export class PageDto {
8
+ }
9
+ export class PageRevisionDto {
10
+ }
11
+ export class PageRevisionSchemaDto {
12
+ }
13
+ export class PageRevisionSchemaPropertyDto {
14
+ }
15
+ export class TTSchemaDto {
16
+ }
17
+ export class TTSchemaProperties {
18
+ }
19
+ export class TTSchemaCustomDto extends TTSchemaDto {
20
+ }
21
+ //# sourceMappingURL=page.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.dto.js","sourceRoot":"","sources":["../../src/page/page.dto.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAQ;CAQpB;AAED,MAAM,OAAO,OAAO;CAMnB;AAED,MAAM,OAAO,UAAU;CAItB;AAED,MAAM,OAAO,OAAO;CA0BnB;AAED,MAAM,OAAO,eAAe;CAI3B;AAED,MAAM,OAAO,qBAAqB;CAQjC;AAED,MAAM,OAAO,6BAA6B;CAMzC;AAED,MAAM,OAAO,WAAW;CAQvB;AAED,MAAM,OAAO,kBAAkB;CAM9B;AAED,MAAM,OAAO,iBAAkB,SAAQ,WAAW;CAYjD"}
@@ -0,0 +1,8 @@
1
+ export declare const DynamicPageFiltering: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<any, import("@urql/core/dist/urql-core-chunk").AnyVariables>;
2
+ export declare const GET_PAGE: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<any, import("@urql/core/dist/urql-core-chunk").AnyVariables>;
3
+ export declare const GET_ERROR_TEMPLATE: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<any, import("@urql/core/dist/urql-core-chunk").AnyVariables>;
4
+ export declare const GET_URL_RESOLUTION: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<any, import("@urql/core/dist/urql-core-chunk").AnyVariables>;
5
+ export declare const GET_LAYOUT_REVISION: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<any, import("@urql/core/dist/urql-core-chunk").AnyVariables>;
6
+ export declare const GET_ASSETS: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<any, import("@urql/core/dist/urql-core-chunk").AnyVariables>;
7
+ export declare const GET_DOMAIN_SITEMAP: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<any, import("@urql/core/dist/urql-core-chunk").AnyVariables>;
8
+ export declare const GET_DOMAIN_ROBOTS: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<any, import("@urql/core/dist/urql-core-chunk").AnyVariables>;
@@ -0,0 +1,216 @@
1
+ import { gql } from '@urql/core';
2
+ export const DynamicPageFiltering = gql `
3
+ query DynamicPageFiltering(
4
+ $latitude: Float
5
+ $longitude: Float
6
+ $pageType: String!
7
+ $domain: String!
8
+ $limitPageId: [Int]
9
+ $query: String
10
+ $radius: Float
11
+ $limit: Int
12
+ $offset: Int
13
+ $filters: JSONObject
14
+ $fields: [String]
15
+ ) {
16
+ publicListPages(
17
+ latitude: $latitude
18
+ longitude: $longitude
19
+ pageType: $pageType
20
+ domain: $domain
21
+ limitPageId: $limitPageId
22
+ query: $query
23
+ radius: $radius
24
+ limit: $limit
25
+ offset: $offset
26
+ filters: $filters
27
+ fields: $fields
28
+ ) {
29
+ items {
30
+ id
31
+ name
32
+ metaTitle
33
+ metaDescription
34
+ allowCrawling
35
+ customProperties
36
+ urlPath
37
+ }
38
+ total
39
+ }
40
+ }
41
+ `;
42
+ const REVISION_SCHEMA_FRAGMENT = gql `
43
+ fragment revisionSchemaFragment on PageRevisionSchemaEntityDto {
44
+ id
45
+ sortOrder
46
+ anchorId
47
+ campaign
48
+ label
49
+ properties {
50
+ fieldId
51
+ name
52
+ value
53
+ }
54
+ ttschema(draftMode: $draftMode) {
55
+ id
56
+ name
57
+ titlePlural
58
+ titleSingular
59
+ type
60
+ fields {
61
+ id
62
+ name
63
+ type
64
+ hasMultipleValues
65
+ typeTTSchema {
66
+ id
67
+ }
68
+ }
69
+ subSchemas {
70
+ id
71
+ name
72
+ titlePlural
73
+ titleSingular
74
+ fields {
75
+ id
76
+ name
77
+ type
78
+ hasMultipleValues
79
+ typeTTSchema {
80
+ id
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ `;
87
+ const REVISION_FRAGMENT = gql `
88
+ fragment revisionFragment on PageRevisionEntityDto {
89
+ id
90
+ schema(draftMode: $draftMode) {
91
+ ...revisionSchemaFragment
92
+ template {
93
+ id
94
+ name
95
+ publishedRevision {
96
+ id
97
+ schema {
98
+ ...revisionSchemaFragment
99
+ }
100
+ }
101
+ }
102
+ }
103
+ }
104
+ ${REVISION_SCHEMA_FRAGMENT}
105
+ `;
106
+ const PAGE_FRAGMENT = gql `
107
+ fragment pageFragment on PageEntityDto {
108
+ id
109
+ name
110
+ urlSegment
111
+ metaTitle
112
+ metaDescription
113
+ allowCrawling
114
+ lang
115
+ brandId
116
+ sitePath
117
+ site {
118
+ id
119
+ name
120
+ customScriptHead
121
+ customScriptBody
122
+ }
123
+ breadcrumbs {
124
+ name
125
+ urlPath
126
+ }
127
+ }
128
+ `;
129
+ export const GET_PAGE = gql `
130
+ query Page(
131
+ $slug: String
132
+ $domain: String
133
+ $id: Int
134
+ $campaignId: Int
135
+ $draftMode: Boolean = false
136
+ ) {
137
+ page(slug: $slug, domain: $domain, id: $id, campaignId: $campaignId) {
138
+ ...pageFragment
139
+ publishedRevision {
140
+ ...revisionFragment
141
+ }
142
+ }
143
+ }
144
+ ${REVISION_FRAGMENT}
145
+ ${PAGE_FRAGMENT}
146
+ `;
147
+ export const GET_ERROR_TEMPLATE = gql `
148
+ query ErrorTemplate(
149
+ $domain: String!
150
+ $path: String!
151
+ $errorType: ErrorTemplateType!
152
+ $draftMode: Boolean = false
153
+ ) {
154
+ errorTemplate(domain: $domain, path: $path, errorType: $errorType) {
155
+ publishedRevision {
156
+ ...revisionFragment
157
+ }
158
+ }
159
+ }
160
+ ${REVISION_FRAGMENT}
161
+ `;
162
+ export const GET_URL_RESOLUTION = gql `
163
+ query UrlResolution($slug: String, $domain: String!, $draftMode: Boolean = false) {
164
+ urlResolution(slug: $slug, domain: $domain) {
165
+ page {
166
+ ...pageFragment
167
+ publishedRevision {
168
+ ...revisionFragment
169
+ }
170
+ }
171
+ redirect {
172
+ target
173
+ type
174
+ }
175
+ }
176
+ }
177
+ ${REVISION_FRAGMENT}
178
+ ${PAGE_FRAGMENT}
179
+ `;
180
+ export const GET_LAYOUT_REVISION = gql `
181
+ query LayoutRevision($id: Int!, $draftMode: Boolean = true, $campaignId: Int, $pageId: Int) {
182
+ pageRevision(id: $id, campaignId: $campaignId, pageId: $pageId) {
183
+ ...revisionFragment
184
+ page {
185
+ ...pageFragment
186
+ }
187
+ }
188
+ }
189
+ ${REVISION_FRAGMENT}
190
+ ${PAGE_FRAGMENT}
191
+ `;
192
+ export const GET_ASSETS = gql `
193
+ query AssetList($ids: [Int!]!) {
194
+ assetList(ids: $ids) {
195
+ id
196
+ url
197
+ altText
198
+ accessLevel
199
+ }
200
+ }
201
+ `;
202
+ export const GET_DOMAIN_SITEMAP = gql `
203
+ query DomainWithSitemap($domain: String!) {
204
+ domain(domain: $domain) {
205
+ sitemap
206
+ }
207
+ }
208
+ `;
209
+ export const GET_DOMAIN_ROBOTS = gql `
210
+ query DomainWithRobot($domain: String!) {
211
+ domain(domain: $domain) {
212
+ robots
213
+ }
214
+ }
215
+ `;
216
+ //# sourceMappingURL=page.query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.query.js","sourceRoot":"","sources":["../../src/page/page.query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCtC,CAAC;AAEF,MAAM,wBAAwB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4CnC,CAAC;AAEF,MAAM,iBAAiB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;IAiBzB,wBAAwB;CAC3B,CAAC;AAEF,MAAM,aAAa,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;CAsBxB,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;IAevB,iBAAiB;IACjB,aAAa;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;;;;;;;;;;;;;IAajC,iBAAiB;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;IAejC,iBAAiB;IACjB,aAAa;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAA;;;;;;;;;IASlC,iBAAiB;IACjB,aAAa;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;;;;;;;;;CAS5B,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;;;;;;CAMpC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAA;;;;;;CAMnC,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { ErrorTemplateType } from '../types.js';
2
+ export declare class PageService {
3
+ private readonly apolloClient;
4
+ private readonly config;
5
+ constructor(uri: string | undefined);
6
+ getPage(slug: string, domain?: string): Promise<any>;
7
+ getPagePreview(id: number, campaignId?: number, draftMode?: boolean): Promise<any>;
8
+ resolveUrl(slug: string, domain?: string): Promise<any>;
9
+ getErrorTemplate(domain: string, path: string, errorType: ErrorTemplateType): Promise<any>;
10
+ getRevision(id: number, pageId?: string, campaignId?: string, draftMode?: boolean): Promise<{
11
+ props: {
12
+ page: {
13
+ id: number;
14
+ metaTitle: string;
15
+ properties: {};
16
+ ttschema: import("./page.dto.js").TTSchemaCustomDto[];
17
+ __typename?: "PageEntityDto";
18
+ name: string;
19
+ urlSegment: string;
20
+ metaDescription?: string;
21
+ allowCrawling?: boolean;
22
+ lang: string;
23
+ brandId: number;
24
+ sitePath?: string;
25
+ site: {
26
+ __typename?: "SiteEntityDto";
27
+ id: number;
28
+ customScriptHead: string;
29
+ customScriptBody: string;
30
+ };
31
+ };
32
+ };
33
+ notFound?: undefined;
34
+ } | {
35
+ props: {
36
+ page: {
37
+ id: number;
38
+ metaTitle: string;
39
+ properties: {};
40
+ ttschema: any[];
41
+ };
42
+ };
43
+ notFound?: undefined;
44
+ } | {
45
+ notFound: boolean;
46
+ props?: undefined;
47
+ }>;
48
+ getSitemap(domain: string): Promise<any>;
49
+ getRobots(domain: string): Promise<any>;
50
+ }