@jsb188/graphql 1.1.10 → 1.1.11

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 (116) hide show
  1. package/cache/config.ts +64 -50
  2. package/cache/index.test.ts +671 -109
  3. package/cache/index.ts +1700 -1240
  4. package/cache/persist.ts +721 -0
  5. package/cache/store.ts +437 -0
  6. package/client/data-table-realtime-subscriptions.test.ts +740 -0
  7. package/client/data-table-realtime-subscriptions.ts +955 -0
  8. package/client/data-table-realtime.test.ts +792 -0
  9. package/client/data-table-realtime.ts +1218 -0
  10. package/client/fragment-realtime-sequence.ts +52 -0
  11. package/client/index.ts +2 -0
  12. package/client/open-sheet.ts +137 -0
  13. package/client/request-managed-session.test.ts +574 -0
  14. package/client/request-no-store.test.ts +157 -0
  15. package/client/request.ts +954 -163
  16. package/client/sse-ticket.test.ts +26 -0
  17. package/deno.lock +170 -0
  18. package/deno.test.json +8 -4
  19. package/drafts/index.ts +149 -0
  20. package/drafts/store.ts +397 -0
  21. package/gql/eagerQueryMap.ts +12 -0
  22. package/gql/fragments/accountAuthFragments.ts +5 -0
  23. package/gql/fragments/accountFragments.ts +0 -3
  24. package/gql/fragments/accountSessionFragments.ts +16 -0
  25. package/gql/fragments/agentDocFragments.ts +46 -0
  26. package/gql/fragments/agentMemoryFragments.ts +19 -0
  27. package/gql/fragments/aiChatFragments.ts +16 -0
  28. package/gql/fragments/billingFragments.ts +0 -11
  29. package/gql/fragments/campaignFragments.ts +277 -0
  30. package/gql/fragments/dataTableFragments.ts +18 -128
  31. package/gql/fragments/emailFragments.ts +19 -9
  32. package/gql/fragments/fieldDocFragments.ts +82 -0
  33. package/gql/fragments/logFragments.ts +20 -79
  34. package/gql/fragments/organizationFragments.ts +43 -5
  35. package/gql/fragments/scheduleFragments.ts +155 -0
  36. package/gql/fragments/sheetFragments.ts +552 -22
  37. package/gql/fragments/storageFragments.ts +21 -0
  38. package/gql/fragments/workflowFragments.ts +28 -4
  39. package/gql/mutations/accountMutations.ts +0 -2
  40. package/gql/mutations/agentDocMutations.ts +177 -0
  41. package/gql/mutations/agentMemoryMutations.ts +36 -0
  42. package/gql/mutations/aiChatMutations.ts +17 -4
  43. package/gql/mutations/authMutations.ts +158 -17
  44. package/gql/mutations/campaignMutations.ts +215 -0
  45. package/gql/mutations/dataTableMutations.ts +48 -26
  46. package/gql/mutations/fieldDocMutations.ts +24 -0
  47. package/gql/mutations/index.ts +6 -1
  48. package/gql/mutations/logMutations.ts +6 -29
  49. package/gql/mutations/organizationMutations.ts +13 -4
  50. package/gql/mutations/scheduleMutations.ts +423 -0
  51. package/gql/mutations/sheetMutations.ts +273 -56
  52. package/gql/mutations/storageMutations.ts +20 -0
  53. package/gql/mutations/workflowMutations.ts +42 -0
  54. package/gql/queries/agentDocQueries.ts +120 -0
  55. package/gql/queries/agentMemoryQueries.ts +22 -0
  56. package/gql/queries/aiChatQueries.ts +18 -2
  57. package/gql/queries/authQueries.ts +41 -0
  58. package/gql/queries/billingQueries.ts +23 -0
  59. package/gql/queries/campaignQueries.ts +127 -0
  60. package/gql/queries/dataTableQueries.ts +100 -11
  61. package/gql/queries/emailQueries.ts +55 -3
  62. package/gql/queries/fieldDocQueries.ts +158 -0
  63. package/gql/queries/index.ts +8 -2
  64. package/gql/queries/logQueries.ts +11 -28
  65. package/gql/queries/organizationQueries.ts +52 -1
  66. package/gql/queries/scheduleQueries.ts +315 -0
  67. package/gql/queries/sheetQueries.ts +336 -25
  68. package/gql/queries/storageQueries.ts +38 -0
  69. package/gql/queries/workflowQueries.ts +72 -3
  70. package/hooks/index.ts +2065 -971
  71. package/hooks/use-account-mtn.ts +76 -81
  72. package/hooks/use-agentDoc-mtn.ts +285 -0
  73. package/hooks/use-agentDoc-qry.ts +208 -0
  74. package/hooks/use-agentMemory-mtn.ts +73 -0
  75. package/hooks/use-agentMemory-qry.ts +44 -0
  76. package/hooks/use-aiChat-mtn.ts +232 -137
  77. package/hooks/use-aiChat-qry.ts +480 -222
  78. package/hooks/use-app-qry.ts +12 -9
  79. package/hooks/use-auth-mtn.ts +406 -252
  80. package/hooks/use-auth-qry.ts +51 -0
  81. package/hooks/use-campaign-mtn.ts +377 -0
  82. package/hooks/use-campaign-qry.ts +257 -0
  83. package/hooks/use-dataTable-mtn.ts +116 -33
  84. package/hooks/use-dataTable-qry.ts +859 -35
  85. package/hooks/use-email-qry.ts +194 -79
  86. package/hooks/use-fieldDoc-mtn.ts +50 -0
  87. package/hooks/use-fieldDoc-qry.ts +180 -0
  88. package/hooks/use-inboundContact-mtn.ts +19 -16
  89. package/hooks/use-inboundContact-qry.ts +63 -55
  90. package/hooks/use-integration-mtn.ts +56 -38
  91. package/hooks/use-integration-qry.ts +24 -9
  92. package/hooks/use-log-mtn.ts +72 -56
  93. package/hooks/use-log-qry.ts +93 -69
  94. package/hooks/use-organization-mtn.ts +334 -277
  95. package/hooks/use-organization-qry.ts +199 -129
  96. package/hooks/use-schedule-mtn.ts +416 -0
  97. package/hooks/use-schedule-qry.ts +157 -0
  98. package/hooks/use-sheet-mtn.ts +233 -47
  99. package/hooks/use-sheet-qry.ts +353 -70
  100. package/hooks/use-storage-mtn.ts +81 -41
  101. package/hooks/use-storage-qry.ts +104 -13
  102. package/hooks/use-workflow-mtn.ts +55 -0
  103. package/hooks/use-workflow-qry.ts +206 -48
  104. package/loaders/campaign.ts +137 -0
  105. package/package.json +94 -71
  106. package/sse.ts +157 -104
  107. package/tsconfig.json +11 -10
  108. package/types.d.ts +60 -30
  109. package/utils.ts +78 -49
  110. package/gql/fragments/productFragments.ts +0 -39
  111. package/gql/fragments/reportFragments.ts +0 -90
  112. package/gql/mutations/billingMutations.ts +0 -34
  113. package/gql/queries/productQueries.ts +0 -31
  114. package/gql/queries/reportQueries.ts +0 -134
  115. package/hooks/use-product-qry.ts +0 -67
  116. package/hooks/use-report-qry.ts +0 -153
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Assert one client-side SSE credential invariant with a useful failure.
3
+ */
4
+ function expect(value: unknown, message: string) {
5
+ if (!value) {
6
+ throw new Error(message);
7
+ }
8
+ }
9
+
10
+ Deno.test('AI chat EventSource URLs contain only the single-use SSE ticket', async () => {
11
+ const runtime = await Deno.readTextFile(
12
+ new URL('../hooks/use-aiChat-qry.ts', import.meta.url),
13
+ );
14
+ expect(
15
+ runtime.includes('session_key: sessionKey'),
16
+ 'AI chat SSE must send its one-time ticket',
17
+ );
18
+ expect(
19
+ !runtime.includes('auth_token'),
20
+ 'AI chat SSE URLs must never contain the reusable access JWT',
21
+ );
22
+ expect(
23
+ !runtime.includes('getAuthToken'),
24
+ 'AI chat SSE must not read a reusable bearer for EventSource query parameters',
25
+ );
26
+ });
package/deno.lock ADDED
@@ -0,0 +1,170 @@
1
+ {
2
+ "version": "5",
3
+ "specifiers": {
4
+ "npm:luxon@3.7.2": "3.7.2",
5
+ "npm:node-polyglot@^2.6.0": "2.6.0"
6
+ },
7
+ "npm": {
8
+ "call-bind-apply-helpers@1.0.2": {
9
+ "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
10
+ "dependencies": [
11
+ "es-errors",
12
+ "function-bind"
13
+ ]
14
+ },
15
+ "call-bind@1.0.9": {
16
+ "integrity": "sha512-a/hy+pNsFUTR+Iz8TCJvXudKVLAnz/DyeSUo10I5yvFDQJBFU2s9uqQpoSrJlroHUKoKqzg+epxyP9lqFdzfBQ==",
17
+ "dependencies": [
18
+ "call-bind-apply-helpers",
19
+ "es-define-property",
20
+ "get-intrinsic",
21
+ "set-function-length"
22
+ ]
23
+ },
24
+ "call-bound@1.0.4": {
25
+ "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
26
+ "dependencies": [
27
+ "call-bind-apply-helpers",
28
+ "get-intrinsic"
29
+ ]
30
+ },
31
+ "define-data-property@1.1.4": {
32
+ "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==",
33
+ "dependencies": [
34
+ "es-define-property",
35
+ "es-errors",
36
+ "gopd"
37
+ ]
38
+ },
39
+ "define-properties@1.2.1": {
40
+ "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==",
41
+ "dependencies": [
42
+ "define-data-property",
43
+ "has-property-descriptors",
44
+ "object-keys"
45
+ ]
46
+ },
47
+ "dunder-proto@1.0.1": {
48
+ "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
49
+ "dependencies": [
50
+ "call-bind-apply-helpers",
51
+ "es-errors",
52
+ "gopd"
53
+ ]
54
+ },
55
+ "es-define-property@1.0.1": {
56
+ "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g=="
57
+ },
58
+ "es-errors@1.3.0": {
59
+ "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw=="
60
+ },
61
+ "es-object-atoms@1.1.2": {
62
+ "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==",
63
+ "dependencies": [
64
+ "es-errors"
65
+ ]
66
+ },
67
+ "function-bind@1.1.2": {
68
+ "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="
69
+ },
70
+ "get-intrinsic@1.3.0": {
71
+ "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
72
+ "dependencies": [
73
+ "call-bind-apply-helpers",
74
+ "es-define-property",
75
+ "es-errors",
76
+ "es-object-atoms",
77
+ "function-bind",
78
+ "get-proto",
79
+ "gopd",
80
+ "has-symbols",
81
+ "hasown",
82
+ "math-intrinsics"
83
+ ]
84
+ },
85
+ "get-proto@1.0.1": {
86
+ "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
87
+ "dependencies": [
88
+ "dunder-proto",
89
+ "es-object-atoms"
90
+ ]
91
+ },
92
+ "gopd@1.2.0": {
93
+ "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg=="
94
+ },
95
+ "has-property-descriptors@1.0.2": {
96
+ "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==",
97
+ "dependencies": [
98
+ "es-define-property"
99
+ ]
100
+ },
101
+ "has-symbols@1.1.0": {
102
+ "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ=="
103
+ },
104
+ "hasown@2.0.4": {
105
+ "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
106
+ "dependencies": [
107
+ "function-bind"
108
+ ]
109
+ },
110
+ "js-tokens@4.0.0": {
111
+ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
112
+ },
113
+ "loose-envify@1.4.0": {
114
+ "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
115
+ "dependencies": [
116
+ "js-tokens"
117
+ ],
118
+ "bin": true
119
+ },
120
+ "luxon@3.7.2": {
121
+ "integrity": "sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew=="
122
+ },
123
+ "math-intrinsics@1.1.0": {
124
+ "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="
125
+ },
126
+ "node-polyglot@2.6.0": {
127
+ "integrity": "sha512-ZZFkaYzIfGfBvSM6QhA9dM8EEaUJOVewzGSRcXWbJELXDj0lajAtKaENCYxvF5yE+TgHg6NQb0CmgYMsMdcNJQ==",
128
+ "dependencies": [
129
+ "hasown",
130
+ "object.entries",
131
+ "warning"
132
+ ]
133
+ },
134
+ "object-keys@1.1.1": {
135
+ "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA=="
136
+ },
137
+ "object.entries@1.1.9": {
138
+ "integrity": "sha512-8u/hfXFRBD1O0hPUjioLhoWFHRmt6tKA4/vZPyckBr18l1KE9uHrFaFaUi8MDRTpi4uak2goyPTSNJLXX2k2Hw==",
139
+ "dependencies": [
140
+ "call-bind",
141
+ "call-bound",
142
+ "define-properties",
143
+ "es-object-atoms"
144
+ ]
145
+ },
146
+ "set-function-length@1.2.2": {
147
+ "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==",
148
+ "dependencies": [
149
+ "define-data-property",
150
+ "es-errors",
151
+ "function-bind",
152
+ "get-intrinsic",
153
+ "gopd",
154
+ "has-property-descriptors"
155
+ ]
156
+ },
157
+ "warning@4.0.3": {
158
+ "integrity": "sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==",
159
+ "dependencies": [
160
+ "loose-envify"
161
+ ]
162
+ }
163
+ },
164
+ "workspace": {
165
+ "dependencies": [
166
+ "npm:luxon@3.7.2",
167
+ "npm:node-polyglot@^2.6.0"
168
+ ]
169
+ }
170
+ }
package/deno.test.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
- "imports": {
3
- "@jsb188/app/": "../@jsb188:app/src/",
4
- "@jsb188/react/": "../@jsb188:react/src/"
5
- }
2
+ "imports": {
3
+ "@jsb188/app": "../@jsb188:app/src/main.ts",
4
+ "@jsb188/app/": "../@jsb188:app/src/",
5
+ "@jsb188/mday/": "../@jsb188:mday/src/",
6
+ "@jsb188/react/": "../@jsb188:react/src/",
7
+ "luxon": "npm:luxon@3.7.2",
8
+ "node-polyglot": "npm:node-polyglot@^2.6.0"
9
+ }
6
10
  }
@@ -0,0 +1,149 @@
1
+ import {
2
+ type DraftSchema,
3
+ mergeSchemaDefaults,
4
+ pruneToSchema,
5
+ } from '@jsb188/app/utils/schema.ts';
6
+ import {
7
+ deleteAllDraftRecords,
8
+ deleteDraftRecord,
9
+ peekDraftRecord,
10
+ readDraftRecord,
11
+ writeDraftRecord,
12
+ } from './store.ts';
13
+
14
+ /**
15
+ * Expiring local objects ("drafts").
16
+ *
17
+ * A draft is one plain object persisted in IndexedDB under a caller-chosen
18
+ * key, readable until its TTL elapses. It exists for editing state that must
19
+ * survive a modal closing, a navigation, or a tab reload without becoming a
20
+ * server-side entity: composer text, selected uploads, form-in-progress.
21
+ *
22
+ * Keys are namespaced by the caller. The convention is
23
+ * "feature:version:scopeId", e.g. `createCampaignTemplate:v1:${orgId}` — the
24
+ * scope segment keeps one organization's draft out of another's, and the
25
+ * version segment is the escape hatch for a shape change the schema cannot
26
+ * catch (a field that keeps its type but changes its meaning).
27
+ *
28
+ * When a schema is passed, it prunes rather than rejects: values that do not
29
+ * match are dropped and everything else is kept, on read and on write alike.
30
+ * A draft written by an older build therefore degrades into a partial draft
31
+ * merged over defaultValue, never into an old shape reaching the UI.
32
+ */
33
+
34
+ export type { DraftSchema, DraftSchemaNode } from '@jsb188/app/utils/schema.ts';
35
+
36
+ export interface DraftOptions<T> {
37
+ /* Returned on a miss; a hit is merged over it, so pruned fields fall back */
38
+ defaultValue?: T | null;
39
+ /* Values that fail the schema are dropped, never rejected wholesale */
40
+ schema?: DraftSchema;
41
+ /* Read: how old a record may be. Write: the sweep hint stored with it */
42
+ ttlHours?: number;
43
+ }
44
+
45
+ export const DRAFT_TTL_HOURS_DEFAULT = 24;
46
+
47
+ /**
48
+ * Apply the schema (when given) and merge the result over the default value.
49
+ */
50
+
51
+ function resolveDraftValue<T>(
52
+ value: unknown,
53
+ options?: DraftOptions<T>,
54
+ ): T | null {
55
+ const defaultValue = options?.defaultValue ?? null;
56
+ const prunedValue = options?.schema
57
+ ? pruneToSchema(value, options.schema)
58
+ : value;
59
+
60
+ if (prunedValue === null || prunedValue === undefined) {
61
+ return defaultValue;
62
+ }
63
+
64
+ if (defaultValue === null) {
65
+ return prunedValue as T;
66
+ }
67
+
68
+ return mergeSchemaDefaults(prunedValue, defaultValue);
69
+ }
70
+
71
+ /**
72
+ * Read one persisted object.
73
+ *
74
+ * Returns defaultValue (or null) when the key is missing, when its record has
75
+ * outlived ttlHours, or when IndexedDB is unavailable. An expired record is
76
+ * removed as part of the read.
77
+ */
78
+
79
+ export async function getDraft<T>(
80
+ key: string,
81
+ options?: DraftOptions<T>,
82
+ ): Promise<T | null> {
83
+ const record = await readDraftRecord(
84
+ key,
85
+ options?.ttlHours ?? DRAFT_TTL_HOURS_DEFAULT,
86
+ );
87
+ return resolveDraftValue<T>(record?.d, options);
88
+ }
89
+
90
+ /**
91
+ * Read one persisted object from the session mirror only.
92
+ *
93
+ * Synchronous, so it can seed React state on the first render, but it only
94
+ * sees keys already read or written in this session; a cold load must still go
95
+ * through getDraft().
96
+ */
97
+
98
+ export function peekDraft<T>(key: string, options?: DraftOptions<T>): T | null {
99
+ const record = peekDraftRecord(
100
+ key,
101
+ options?.ttlHours ?? DRAFT_TTL_HOURS_DEFAULT,
102
+ );
103
+ return resolveDraftValue<T>(record?.d, options);
104
+ }
105
+
106
+ /**
107
+ * Write one persisted object, keeping only the values that pass the schema.
108
+ *
109
+ * defaultValue is ignored here; defaults are a read-time concern. Writes are
110
+ * immediate, so a caller writing on every keystroke should debounce.
111
+ */
112
+
113
+ export async function setDraft<T>(
114
+ key: string,
115
+ value: T,
116
+ options?: DraftOptions<T>,
117
+ ): Promise<void> {
118
+ const prunedValue = options?.schema
119
+ ? pruneToSchema(value, options.schema)
120
+ : value;
121
+ if (prunedValue === null || prunedValue === undefined) {
122
+ // Nothing survived the schema; a stored draft would only resurrect a
123
+ // shape the caller no longer holds
124
+ await deleteDraftRecord(key);
125
+ return;
126
+ }
127
+
128
+ await writeDraftRecord(
129
+ key,
130
+ prunedValue,
131
+ options?.ttlHours ?? DRAFT_TTL_HOURS_DEFAULT,
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Remove one persisted object.
137
+ */
138
+
139
+ export function deleteDraft(key: string): Promise<void> {
140
+ return deleteDraftRecord(key);
141
+ }
142
+
143
+ /**
144
+ * Remove every persisted object (sign-out, account access revoked).
145
+ */
146
+
147
+ export function clearAllDrafts() {
148
+ deleteAllDraftRecords();
149
+ }