@vrplatform/graphql 1.0.8 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/build/main/client/headers.d.ts +3 -0
  2. package/build/main/client/headers.js +42 -0
  3. package/build/main/client/index.d.ts +13 -0
  4. package/build/main/client/index.js +103 -0
  5. package/build/main/client/subscription.d.ts +3 -0
  6. package/build/main/client/subscription.js +29 -0
  7. package/build/main/common/account.d.ts +2 -0
  8. package/build/main/common/account.js +7 -0
  9. package/build/main/common/address.d.ts +9 -0
  10. package/build/main/common/address.js +2 -0
  11. package/build/main/common/bank-record.d.ts +2 -0
  12. package/build/main/common/bank-record.js +7 -0
  13. package/build/main/common/index.d.ts +5 -0
  14. package/build/main/common/index.js +21 -0
  15. package/build/main/common/listings.d.ts +4 -0
  16. package/build/main/common/listings.js +99 -0
  17. package/build/main/common/tenant.d.ts +19 -0
  18. package/build/main/common/tenant.js +85 -0
  19. package/build/main/error.d.ts +2 -0
  20. package/build/main/error.js +6 -0
  21. package/build/main/gqty/index.d.ts +7 -0
  22. package/build/main/gqty/index.js +48 -0
  23. package/build/main/gqty/schema.generated.d.ts +39464 -46636
  24. package/build/main/gqty/schema.generated.js +10450 -14093
  25. package/build/main/index.d.ts +4 -14
  26. package/build/main/index.js +7 -75
  27. package/build/main/tsconfig.main.tsbuildinfo +1 -1
  28. package/build/main/types.d.ts +5 -6
  29. package/build/main/wrap.d.ts +12 -0
  30. package/build/main/wrap.js +47 -0
  31. package/build/module/client/headers.d.ts +3 -0
  32. package/build/module/client/headers.js +39 -0
  33. package/build/module/client/index.d.ts +13 -0
  34. package/build/module/client/index.js +98 -0
  35. package/build/module/client/subscription.d.ts +3 -0
  36. package/build/module/client/subscription.js +26 -0
  37. package/build/module/common/account.d.ts +2 -0
  38. package/build/module/common/account.js +4 -0
  39. package/build/module/common/address.d.ts +9 -0
  40. package/build/module/common/address.js +1 -0
  41. package/build/module/common/bank-record.d.ts +2 -0
  42. package/build/module/common/bank-record.js +4 -0
  43. package/build/module/common/index.d.ts +5 -0
  44. package/build/module/common/index.js +5 -0
  45. package/build/module/common/listings.d.ts +4 -0
  46. package/build/module/common/listings.js +93 -0
  47. package/build/module/common/tenant.d.ts +19 -0
  48. package/build/module/common/tenant.js +77 -0
  49. package/build/module/error.d.ts +2 -0
  50. package/build/module/error.js +2 -0
  51. package/build/module/gqty/index.d.ts +7 -0
  52. package/build/module/gqty/index.js +41 -0
  53. package/build/module/gqty/schema.generated.d.ts +39464 -46636
  54. package/build/module/gqty/schema.generated.js +10450 -14093
  55. package/build/module/index.d.ts +4 -14
  56. package/build/module/index.js +4 -72
  57. package/build/module/tsconfig.esm.tsbuildinfo +1 -1
  58. package/build/module/types.d.ts +5 -6
  59. package/build/module/wrap.d.ts +12 -0
  60. package/build/module/wrap.js +44 -0
  61. package/package.json +25 -35
  62. package/src/client/headers.ts +51 -0
  63. package/src/client/index.ts +152 -0
  64. package/src/client/subscription.ts +34 -0
  65. package/src/common/account.ts +6 -0
  66. package/src/common/address.ts +9 -0
  67. package/src/common/bank-record.ts +6 -0
  68. package/src/common/index.ts +5 -0
  69. package/src/common/listings.ts +106 -0
  70. package/src/common/tenant.ts +101 -0
  71. package/src/error.ts +1 -0
  72. package/src/gqty/index.ts +62 -0
  73. package/src/gqty/schema.generated.d.ts +39464 -46636
  74. package/src/gqty/schema.generated.js +10472 -14099
  75. package/src/index.ts +9 -94
  76. package/src/types.ts +6 -10
  77. package/src/wrap.ts +67 -0
  78. package/LICENSE +0 -3
  79. package/build/main/create-client.d.ts +0 -6
  80. package/build/main/create-client.js +0 -107
  81. package/build/main/gqty/error.d.ts +0 -6
  82. package/build/main/gqty/error.js +0 -48
  83. package/build/module/create-client.d.ts +0 -6
  84. package/build/module/create-client.js +0 -104
  85. package/build/module/gqty/error.d.ts +0 -6
  86. package/build/module/gqty/error.js +0 -40
  87. package/src/create-client.ts +0 -120
  88. package/src/gqty/error.ts +0 -54
@@ -1,15 +1,5 @@
1
- export { useHasuraClientInner } from './create-client';
1
+ export { GQtyClient, GQtyError, ResolveOptions, SubscriptionsClient, } from 'gqty';
2
+ export { type HasuraClient, useHasuraClient } from './client';
3
+ export * from './common';
2
4
  export * from './gqty';
3
- export { GQtyError } from 'gqty';
4
- import type { LegacyResolveOptions } from 'gqty';
5
- import type { Mutation, Query, Subscription } from './gqty';
6
- import type { GqlAuthParam } from './types';
7
- export type ResolveOptionsWithSession<T> = LegacyResolveOptions<T>;
8
- export type HasuraClient = ReturnType<typeof useHasuraClient>;
9
- export declare function useHasuraClient(args?: GqlAuthParam): {
10
- client: import("gqty").GQtyClient<import("./gqty").GeneratedSchema>;
11
- subscriptionsClient: import("graphql-ws").Client;
12
- mutate<T = unknown>(resolved: (sub: Mutation) => T, options?: ResolveOptionsWithSession<T>): Promise<T>;
13
- query<T = unknown>(resolved: (sub: Query) => T, options?: ResolveOptionsWithSession<T>): Promise<T>;
14
- subscribe<T = unknown>(resolved: (sub: Subscription) => T, onData: (data: T, unsubscribeFn: () => Promise<void>) => void, onError?: (err: Error, unsubscribeFn: () => Promise<void>) => void): () => Promise<void>;
15
- };
5
+ export { type ResolveOptionsWithSession, wrapGraphQLClient } from './wrap';
@@ -14,80 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.GQtyError = exports.useHasuraClientInner = void 0;
18
- exports.useHasuraClient = useHasuraClient;
19
- const create_client_1 = require("./create-client");
20
- var create_client_2 = require("./create-client");
21
- Object.defineProperty(exports, "useHasuraClientInner", { enumerable: true, get: function () { return create_client_2.useHasuraClientInner; } });
22
- __exportStar(require("./gqty"), exports);
17
+ exports.wrapGraphQLClient = exports.useHasuraClient = exports.GQtyError = void 0;
23
18
  var gqty_1 = require("gqty");
24
19
  Object.defineProperty(exports, "GQtyError", { enumerable: true, get: function () { return gqty_1.GQtyError; } });
25
- function useHasuraClient(args) {
26
- const { client, subscriptionsClient } = (0, create_client_1.useHasuraClientInner)(args);
27
- const retries = args.retries || 3;
28
- return {
29
- client,
30
- subscriptionsClient,
31
- async mutate(resolved, options) {
32
- if (!options)
33
- options = {};
34
- if (options.noCache === undefined)
35
- options.noCache = true;
36
- let err;
37
- for (let tries = 1; tries <= retries; tries++) {
38
- try {
39
- const result = await client.resolve(({ mutation }) => resolved(mutation), options);
40
- return result;
41
- }
42
- catch (error) {
43
- err = error;
44
- if (error.message !== 'database query error')
45
- break;
46
- await new Promise((resolve) => setTimeout(resolve, 1000 * tries + 1000));
47
- }
48
- }
49
- if (args.onError)
50
- throw args.onError(err) || err;
51
- throw err;
52
- },
53
- async query(resolved, options) {
54
- let err;
55
- for (let tries = 1; tries <= retries; tries++) {
56
- try {
57
- const result = await client.resolve(({ query }) => resolved(query), options);
58
- return result;
59
- }
60
- catch (error) {
61
- err = error;
62
- if (error.message !== 'database query error')
63
- break;
64
- await new Promise((resolve) => setTimeout(resolve, 1000 * tries + 1000));
65
- }
66
- }
67
- if (args.onError)
68
- throw args.onError(err) || err;
69
- throw err;
70
- },
71
- subscribe(resolved, onData, onError) {
72
- if (!subscriptionsClient)
73
- throw new Error('Subscriptions not enabled');
74
- let unsub;
75
- const stop = async () => {
76
- if (!unsub)
77
- return;
78
- await unsub().catch(() => undefined);
79
- };
80
- client.resolved(() => resolved(client.subscription), {
81
- onSubscription(event) {
82
- if (event.unsubscribe)
83
- unsub = event.unsubscribe;
84
- if (event.type === 'data')
85
- onData(event.data, stop);
86
- else if (event.type === 'with-errors' && onError)
87
- onError(event.error, stop);
88
- },
89
- });
90
- return stop;
91
- },
92
- };
93
- }
20
+ var client_1 = require("./client");
21
+ Object.defineProperty(exports, "useHasuraClient", { enumerable: true, get: function () { return client_1.useHasuraClient; } });
22
+ __exportStar(require("./common"), exports);
23
+ __exportStar(require("./gqty"), exports);
24
+ var wrap_1 = require("./wrap");
25
+ Object.defineProperty(exports, "wrapGraphQLClient", { enumerable: true, get: function () { return wrap_1.wrapGraphQLClient; } });
@@ -1 +1 @@
1
- {"root":["../../src/constants.ts","../../src/create-client.ts","../../src/index.ts","../../src/types.ts","../../src/gqty/error.ts","../../src/gqty/index.ts","../../src/gqty/schema.generated.d.ts","../../src/gqty/schema.generated.js"],"version":"5.6.3"}
1
+ {"root":["../../src/constants.ts","../../src/error.ts","../../src/index.ts","../../src/types.ts","../../src/wrap.ts","../../src/client/headers.ts","../../src/client/index.ts","../../src/client/subscription.ts","../../src/common/account.ts","../../src/common/address.ts","../../src/common/bank-record.ts","../../src/common/index.ts","../../src/common/listings.ts","../../src/common/tenant.ts","../../src/gqty/index.ts","../../src/gqty/schema.generated.d.ts","../../src/gqty/schema.generated.js"],"version":"5.9.2"}
@@ -1,16 +1,15 @@
1
1
  export type Headers = {
2
2
  [s: string]: string;
3
3
  };
4
+ export type AllowedHeaders = {
5
+ [s: string]: string;
6
+ } | (() => Headers) | (() => Promise<Headers>);
4
7
  export type GqlAuthParam = {
5
8
  accessToken?: string;
6
9
  secret?: string;
7
- headers?: {
8
- [s: string]: string;
9
- } | (() => Headers) | (() => Promise<Headers>);
10
- fetch?: any;
10
+ headers?: AllowedHeaders;
11
11
  subscriptions?: boolean;
12
12
  uri?: string;
13
- onError?: (err: Error) => any;
14
- retries?: number;
15
13
  auditUserId?: string;
14
+ credentials?: RequestCredentials;
16
15
  };
@@ -0,0 +1,12 @@
1
+ import type { GQtyClient, ResolveOptions, SubscriptionsClient } from 'gqty';
2
+ import type { GeneratedSchema } from './gqty';
3
+ export type ResolveOptionsWithSession<T> = ResolveOptions<T>;
4
+ type Client = GQtyClient<GeneratedSchema>;
5
+ export declare function wrapGraphQLClient(getClient: () => Client, subscriptionsClient?: SubscriptionsClient): {
6
+ readonly client: Client;
7
+ subscriptionsClient: SubscriptionsClient;
8
+ mutate<T = unknown>(resolved: (sub: Client["mutation"]) => T, options?: ResolveOptionsWithSession<T>): Promise<T>;
9
+ query<T = unknown>(resolved: (sub: Client["query"]) => T, options?: ResolveOptionsWithSession<T>): Promise<T>;
10
+ subscribe<T = unknown>(resolved: (sub: Client["subscription"]) => T, onData: (data: T, unsubscribeFn: () => Promise<void>) => void, onError?: (err: Error, unsubscribeFn: () => Promise<void>) => void): () => Promise<void>;
11
+ };
12
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapGraphQLClient = wrapGraphQLClient;
4
+ function wrapGraphQLClient(getClient, subscriptionsClient) {
5
+ return {
6
+ get client() {
7
+ return getClient();
8
+ },
9
+ subscriptionsClient,
10
+ async mutate(resolved, options) {
11
+ if (!options)
12
+ options = {};
13
+ if (options.noCache === undefined)
14
+ options.noCache = true;
15
+ const client = getClient();
16
+ const result = await client.resolved(() => resolved(client.mutation), options);
17
+ return result;
18
+ },
19
+ async query(resolved, options) {
20
+ const client = getClient();
21
+ const result = await client.resolved(() => resolved(client.query), options);
22
+ return result;
23
+ },
24
+ subscribe(resolved, onData, onError) {
25
+ if (!subscriptionsClient)
26
+ throw new Error('Subscriptions not enabled');
27
+ let unsub;
28
+ const stop = async () => {
29
+ if (!unsub)
30
+ return;
31
+ await unsub().catch(() => undefined);
32
+ };
33
+ const client = getClient();
34
+ client.resolved(() => resolved(client.subscription), {
35
+ onSubscription(event) {
36
+ if (event.unsubscribe)
37
+ unsub = event.unsubscribe;
38
+ if (event.type === 'data')
39
+ onData(event.data, stop);
40
+ else if (event.type === 'with-errors' && onError)
41
+ onError(event.error, stop);
42
+ },
43
+ });
44
+ return stop;
45
+ },
46
+ };
47
+ }
@@ -0,0 +1,3 @@
1
+ import type { GqlAuthParam, Headers } from '../types';
2
+ export declare function createHeadersFactory(args?: Pick<GqlAuthParam, 'headers' | 'secret' | 'accessToken' | 'auditUserId'>): (base?: Headers) => Promise<Headers>;
3
+ export type HeadersFactory = ReturnType<typeof createHeadersFactory>;
@@ -0,0 +1,39 @@
1
+ // Create headers factory function
2
+ export function createHeadersFactory(args) {
3
+ return async (base) => {
4
+ const result = {};
5
+ // Add static or function headers
6
+ if (args?.headers) {
7
+ if (typeof args.headers === 'function') {
8
+ const functionResult = await args.headers();
9
+ for (const key in functionResult) {
10
+ result[key] = functionResult[key];
11
+ }
12
+ }
13
+ else {
14
+ for (const key in args.headers) {
15
+ result[key] = args.headers[key];
16
+ }
17
+ }
18
+ }
19
+ // Add base headers
20
+ if (base) {
21
+ for (const key in base) {
22
+ result[key] = base[key];
23
+ }
24
+ }
25
+ // Add auth headers
26
+ if (args?.secret) {
27
+ result['x-hasura-admin-secret'] = args.secret;
28
+ }
29
+ else if (args?.accessToken) {
30
+ result.authorization = args.accessToken.startsWith('Bearer ')
31
+ ? args.accessToken
32
+ : `Bearer ${args.accessToken}`;
33
+ }
34
+ if (args?.auditUserId) {
35
+ result['x-hasura-audit-user-id'] = args.auditUserId;
36
+ }
37
+ return result;
38
+ };
39
+ }
@@ -0,0 +1,13 @@
1
+ import { type RetryableFetchParams } from '@finalytic/utils';
2
+ import { type GQtyClient } from 'gqty';
3
+ import { type GeneratedSchema } from '../gqty';
4
+ import type { GqlAuthParam } from '../types';
5
+ export type HasuraClient = ReturnType<typeof useHasuraClient>;
6
+ export declare const defaultAssertHasuraRetryableResponse: RetryableFetchParams['assertResponse'];
7
+ export declare function useHasuraClient({ uri, secret, auditUserId, accessToken, subscriptions, headers, credentials, ...retryableFetchArgs }?: GqlAuthParam & RetryableFetchParams): {
8
+ readonly client: GQtyClient<GeneratedSchema>;
9
+ subscriptionsClient: import("gqty").SubscriptionsClient;
10
+ mutate<T = unknown>(resolved: (sub: import("../gqty").Mutation) => T, options?: import("../wrap").ResolveOptionsWithSession<T>): Promise<T>;
11
+ query<T = unknown>(resolved: (sub: import("../gqty").Query) => T, options?: import("../wrap").ResolveOptionsWithSession<T>): Promise<T>;
12
+ subscribe<T = unknown>(resolved: (sub: import("../gqty").Subscription) => T, onData: (data: T, unsubscribeFn: () => Promise<void>) => void, onError?: (err: Error, unsubscribeFn: () => Promise<void>) => void): () => Promise<void>;
13
+ };
@@ -0,0 +1,98 @@
1
+ import { defaultAssertRetryableResponse, formatResponse, useRetryableFetch, } from '@finalytic/utils';
2
+ import { createClient } from 'gqty';
3
+ import { hasuraGraphqlUri, hasuraQueryTypeHeader } from '../constants';
4
+ import { generatedSchema, scalarsEnumsHash, } from '../gqty';
5
+ import { wrapGraphQLClient } from '../wrap';
6
+ import { createHeadersFactory } from './headers';
7
+ import { createHasuraSubscriptionsClient } from './subscription';
8
+ const retryablesErrors = [
9
+ 'deadlock detected',
10
+ 'fetch failed',
11
+ 'Unexpected token',
12
+ 'operation exceeded the time limit',
13
+ ];
14
+ function isRetryableResponse(json) {
15
+ if (!json || typeof json !== 'object')
16
+ return null;
17
+ const message = JSON.stringify(json.errors || {});
18
+ if (!message)
19
+ return null;
20
+ return retryablesErrors.find((e) => message?.includes(e));
21
+ }
22
+ export const defaultAssertHasuraRetryableResponse = async (arg) => {
23
+ const defaultResponse = await defaultAssertRetryableResponse(arg);
24
+ if (defaultResponse && 'retryable' in defaultResponse)
25
+ return defaultResponse;
26
+ const json = await formatResponse(arg.response).catch(() => null);
27
+ arg.response.json = () => json;
28
+ const retryableResponse = isRetryableResponse(json);
29
+ if (retryableResponse) {
30
+ return {
31
+ retryable: true,
32
+ errorMessage: retryableResponse,
33
+ errorDetails: json,
34
+ };
35
+ }
36
+ };
37
+ export function useHasuraClient({ uri = hasuraGraphqlUri, secret, auditUserId, accessToken, subscriptions, headers, credentials, ...retryableFetchArgs } = {}) {
38
+ const getHeaders = createHeadersFactory({
39
+ accessToken,
40
+ auditUserId,
41
+ headers,
42
+ secret,
43
+ });
44
+ // Create the subscriptions client if needed
45
+ const subscriptionsClient = createHasuraSubscriptionsClient(uri, getHeaders, subscriptions !== false);
46
+ const fetchFn = retryableFetchArgs.fetch || fetch;
47
+ const attempts = retryableFetchArgs.attempts === undefined ? 3 : retryableFetchArgs.attempts;
48
+ const retryableFetch = attempts > 1
49
+ ? useRetryableFetch({
50
+ assertResponse: defaultAssertHasuraRetryableResponse,
51
+ ...retryableFetchArgs,
52
+ attempts,
53
+ })
54
+ : undefined;
55
+ // Create the GQty client
56
+ const client = () => createClient({
57
+ schema: generatedSchema,
58
+ scalarsEnumsHash,
59
+ async queryFetcher(query, variables, fetchOptions) {
60
+ const getRequest = async () => {
61
+ const headers = await getHeaders({
62
+ 'Content-Type': 'application/json',
63
+ });
64
+ if (fetchOptions?.headers) {
65
+ for (const key in fetchOptions.headers) {
66
+ headers[key] = fetchOptions.headers[key];
67
+ }
68
+ }
69
+ const isMutation = query.includes('mutation');
70
+ headers[hasuraQueryTypeHeader] = isMutation ? 'mutation' : 'query';
71
+ return new Request(uri, {
72
+ method: 'POST',
73
+ credentials,
74
+ headers,
75
+ body: JSON.stringify({
76
+ query,
77
+ variables,
78
+ }),
79
+ });
80
+ };
81
+ const response = retryableFetch
82
+ ? await retryableFetch(getRequest)
83
+ : await fetchFn(await getRequest());
84
+ const json = await response.json();
85
+ return json;
86
+ },
87
+ subscriptionsClient,
88
+ normalization: false,
89
+ defaults: {
90
+ resolved: {
91
+ noCache: true,
92
+ retry: false, // We're handling retries ourselves in queryFetcher
93
+ },
94
+ },
95
+ retry: { maxRetries: 0 },
96
+ });
97
+ return wrapGraphQLClient(client, subscriptionsClient);
98
+ }
@@ -0,0 +1,3 @@
1
+ import type { SubscriptionsClient } from 'gqty';
2
+ import type { Headers } from '../types';
3
+ export declare function createHasuraSubscriptionsClient(uri: string, getHeaders: (base?: Headers) => Promise<Headers>, enabled?: boolean): SubscriptionsClient | undefined;
@@ -0,0 +1,26 @@
1
+ import { createSubscriptionsClient } from '@gqty/subscriptions';
2
+ import { hasuraQueryTypeHeader } from '../constants';
3
+ // Create subscriptions client
4
+ export function createHasuraSubscriptionsClient(uri, getHeaders, enabled = true) {
5
+ // Ensure we strictly check for false, not falsy values
6
+ if (enabled === false) {
7
+ // We must return undefined here, not a client when disabled
8
+ return undefined;
9
+ }
10
+ try {
11
+ const wsUrl = new URL(uri);
12
+ wsUrl.protocol = wsUrl.protocol
13
+ .replace('https', 'wss')
14
+ .replace('http', 'ws');
15
+ return createSubscriptionsClient({
16
+ wsEndpoint: wsUrl.href,
17
+ connectionInitPayload: async () => ({
18
+ headers: await getHeaders({ [hasuraQueryTypeHeader]: 'subscription' }),
19
+ }),
20
+ });
21
+ }
22
+ catch (error) {
23
+ console.error('Failed to create subscriptions client:', error);
24
+ return undefined;
25
+ }
26
+ }
@@ -0,0 +1,2 @@
1
+ import type { account_order_by } from '../gqty';
2
+ export declare const defaultAccountOrderBy: account_order_by[];
@@ -0,0 +1,4 @@
1
+ export const defaultAccountOrderBy = [
2
+ { category: { index: 'asc' } },
3
+ { title: 'asc' },
4
+ ];
@@ -0,0 +1,9 @@
1
+ export type Address = {
2
+ full: string;
3
+ line1: string;
4
+ line2: string | undefined;
5
+ city: string;
6
+ postalCode: string;
7
+ stateCode: string;
8
+ countryCode: string;
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { bankRecord_order_by } from '../gqty';
2
+ export declare const defaultBankRecordOrderBy: bankRecord_order_by[];
@@ -0,0 +1,4 @@
1
+ export const defaultBankRecordOrderBy = [
2
+ { date: 'desc' },
3
+ { uniqueRef: 'desc' },
4
+ ];
@@ -0,0 +1,5 @@
1
+ export * from './account';
2
+ export * from './address';
3
+ export * from './bank-record';
4
+ export * from './listings';
5
+ export * from './tenant';
@@ -0,0 +1,5 @@
1
+ export * from './account';
2
+ export * from './address';
3
+ export * from './bank-record';
4
+ export * from './listings';
5
+ export * from './tenant';
@@ -0,0 +1,4 @@
1
+ import type { listing_bool_exp } from '../gqty';
2
+ export declare function whereListingIsActive(): listing_bool_exp;
3
+ export declare function whereGlListingIsActive(where?: listing_bool_exp, date?: string): listing_bool_exp;
4
+ export declare const whereGlListingIsInactive: (where?: listing_bool_exp, date?: string, includeUpcoming?: boolean) => listing_bool_exp;
@@ -0,0 +1,93 @@
1
+ import { hasValue, utc } from '@finalytic/utils';
2
+ export function whereListingIsActive() {
3
+ return {
4
+ _or: [
5
+ {
6
+ // LEGACY teams
7
+ tenant: {
8
+ isGeneralLedger: { _eq: false },
9
+ },
10
+ calculatedStatus: { _eq: 'active' },
11
+ },
12
+ {
13
+ // GL teams
14
+ tenant: {
15
+ isGeneralLedger: { _eq: true },
16
+ },
17
+ ...whereGlListingIsActive(undefined, utc().yyyymmdd()),
18
+ },
19
+ ],
20
+ };
21
+ }
22
+ export function whereGlListingIsActive(where, date = utc().yyyymmdd()) {
23
+ const statusWhere = {
24
+ _or: [
25
+ {
26
+ _not: {
27
+ ownershipPeriods: {},
28
+ },
29
+ },
30
+ {
31
+ ownershipPeriods: {
32
+ setListingInactive: { _eq: false },
33
+ _or: [
34
+ {
35
+ startAt: {
36
+ _lt: date,
37
+ },
38
+ endAt: {
39
+ _gte: date,
40
+ },
41
+ },
42
+ {
43
+ startAt: {
44
+ _lt: date,
45
+ },
46
+ endAt: {
47
+ _is_null: true,
48
+ },
49
+ },
50
+ ],
51
+ },
52
+ },
53
+ ],
54
+ };
55
+ if (where)
56
+ return { _and: [statusWhere, where] };
57
+ return statusWhere;
58
+ }
59
+ export const whereGlListingIsInactive = (where, date = utc().yyyymmdd(), includeUpcoming = false) => {
60
+ const statusWhere = {
61
+ ownershipPeriods: {
62
+ setListingInactive: { _eq: true },
63
+ _or: [
64
+ includeUpcoming
65
+ ? {
66
+ startAt: {
67
+ _gte: date,
68
+ },
69
+ }
70
+ : undefined,
71
+ {
72
+ startAt: {
73
+ _lt: date,
74
+ },
75
+ endAt: {
76
+ _gte: date,
77
+ },
78
+ },
79
+ {
80
+ startAt: {
81
+ _lt: date,
82
+ },
83
+ endAt: {
84
+ _is_null: true,
85
+ },
86
+ },
87
+ ].filter(hasValue),
88
+ },
89
+ };
90
+ if (where)
91
+ return { _and: [statusWhere, where] };
92
+ return statusWhere;
93
+ };
@@ -0,0 +1,19 @@
1
+ import type { tenant_bool_exp } from '../gqty';
2
+ export declare const VRP_TENANT_ID = "7bfec41f-aa3f-4602-95d2-f7996e4f0e59";
3
+ export declare const DEMO_TEST_PARTNER_TENANT_ID = "0b6a7bd6-56cc-46b5-b2ab-1bd7d1e994fa";
4
+ export declare const XIMPLIFI_TENANT_ID = "d6ab2bbe-e0fc-48d9-89a3-c3c05f4e79b5";
5
+ export declare function whereTenantActive(where?: tenant_bool_exp): tenant_bool_exp;
6
+ export declare function assertTenantActive(tenant: {
7
+ calculatedStatus?: string;
8
+ calculatedBillingPartner?: {
9
+ calculatedStatus?: string;
10
+ };
11
+ }): void;
12
+ export declare function mapTenantStatus(tenant: {
13
+ calculatedStatus?: string;
14
+ calculatedBillingPartner?: {
15
+ calculatedStatus?: string;
16
+ };
17
+ }): 'active' | 'inactive';
18
+ export declare function whereTenantNotTestTeam(where?: tenant_bool_exp): tenant_bool_exp;
19
+ export declare function whereTenantShouldBePaid(where?: tenant_bool_exp, includePartnerTeams?: boolean): tenant_bool_exp;
@@ -0,0 +1,77 @@
1
+ import { utc } from '@finalytic/utils';
2
+ import { HasuraError } from '../error';
3
+ // Tenants
4
+ export const VRP_TENANT_ID = '7bfec41f-aa3f-4602-95d2-f7996e4f0e59';
5
+ export const DEMO_TEST_PARTNER_TENANT_ID = '0b6a7bd6-56cc-46b5-b2ab-1bd7d1e994fa';
6
+ export const XIMPLIFI_TENANT_ID = 'd6ab2bbe-e0fc-48d9-89a3-c3c05f4e79b5';
7
+ export function whereTenantActive(where) {
8
+ const statusWhere = {
9
+ calculatedStatus: { _eq: 'active' },
10
+ _or: [
11
+ {
12
+ calculatedBillingPartner: { calculatedStatus: { _eq: 'active' } },
13
+ },
14
+ {
15
+ calculatedBillingPartnerId: { _is_null: true },
16
+ },
17
+ ],
18
+ };
19
+ if (where)
20
+ return { _and: [statusWhere, where] };
21
+ return statusWhere;
22
+ }
23
+ export function assertTenantActive(tenant) {
24
+ if (tenant.calculatedStatus !== 'active' ||
25
+ tenant.calculatedBillingPartner?.calculatedStatus !== 'active')
26
+ throw new HasuraError('Tenant or billing partner are not active');
27
+ }
28
+ export function mapTenantStatus(tenant) {
29
+ const status = tenant.calculatedStatus === 'active';
30
+ const partnerStatus = tenant.calculatedBillingPartner?.calculatedStatus;
31
+ return status && partnerStatus === 'active' ? 'active' : 'inactive';
32
+ }
33
+ export function whereTenantNotTestTeam(where) {
34
+ const statusWhere = {
35
+ id: { _nin: [VRP_TENANT_ID, DEMO_TEST_PARTNER_TENANT_ID] },
36
+ partnerId: {
37
+ _neq: DEMO_TEST_PARTNER_TENANT_ID,
38
+ },
39
+ _or: [
40
+ { billingPartnerId: { _neq: DEMO_TEST_PARTNER_TENANT_ID } },
41
+ { billingPartnerId: { _is_null: true } },
42
+ ],
43
+ };
44
+ if (where)
45
+ return { _and: [statusWhere, where] };
46
+ return statusWhere;
47
+ }
48
+ export function whereTenantShouldBePaid(where, includePartnerTeams = false) {
49
+ let statusWhere = {
50
+ isOnboarding: {
51
+ _eq: false, // has left onboarding
52
+ },
53
+ // tenant has no trial or trial ended
54
+ _or: [
55
+ {
56
+ trialUntil: {
57
+ _lt: utc().yyyymmdd(),
58
+ },
59
+ },
60
+ {
61
+ trialUntil: {
62
+ _is_null: true,
63
+ },
64
+ },
65
+ ],
66
+ };
67
+ if (!includePartnerTeams)
68
+ statusWhere = {
69
+ ...statusWhere,
70
+ calculatedIsBillable: {
71
+ _eq: true, // no partner teams
72
+ },
73
+ };
74
+ if (where)
75
+ statusWhere = { _and: [statusWhere, where] };
76
+ return whereTenantActive(statusWhere);
77
+ }
@@ -0,0 +1,2 @@
1
+ export declare class HasuraError extends Error {
2
+ }
@@ -0,0 +1,2 @@
1
+ export class HasuraError extends Error {
2
+ }
@@ -1 +1,8 @@
1
+ /**
2
+ * GQTY: You can safely modify this file and Query Fetcher based on your needs
3
+ */
4
+ import type { GeneratedSchema } from './schema.generated';
5
+ export declare const client: import("gqty").GQtyClient<GeneratedSchema>;
6
+ declare const query: import("./schema.generated").Query, mutation: import("./schema.generated").Mutation, mutate: import("gqty").Mutate<GeneratedSchema>, subscription: import("./schema.generated").Subscription, resolved: import("gqty").Resolved, refetch: import("gqty").Refetch, track: import("gqty/Helpers/track").Track;
7
+ export { query, mutation, mutate, subscription, resolved, refetch, track };
1
8
  export * from './schema.generated';