@dereekb/firebase-server 13.2.2 → 13.3.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.
Files changed (166) hide show
  1. package/index.cjs.js +7506 -1884
  2. package/index.esm.js +7505 -1890
  3. package/mailgun/index.cjs.js +333 -31
  4. package/mailgun/index.esm.js +333 -31
  5. package/mailgun/package.json +8 -8
  6. package/mailgun/src/lib/auth.mailgun.d.ts +22 -3
  7. package/model/index.cjs.js +11334 -3830
  8. package/model/index.esm.js +11338 -3834
  9. package/model/package.json +10 -10
  10. package/model/src/lib/mailgun/notification.send.service.mailgun.d.ts +27 -1
  11. package/model/src/lib/notification/notification.action.init.service.d.ts +93 -1
  12. package/model/src/lib/notification/notification.action.service.d.ts +151 -2
  13. package/model/src/lib/notification/notification.config.d.ts +19 -7
  14. package/model/src/lib/notification/notification.config.service.d.ts +44 -6
  15. package/model/src/lib/notification/notification.create.run.d.ts +33 -5
  16. package/model/src/lib/notification/notification.error.d.ts +63 -0
  17. package/model/src/lib/notification/notification.module.d.ts +11 -0
  18. package/model/src/lib/notification/notification.send.d.ts +8 -1
  19. package/model/src/lib/notification/notification.send.service.d.ts +7 -1
  20. package/model/src/lib/notification/notification.send.service.notificationsummary.d.ts +32 -2
  21. package/model/src/lib/notification/notification.send.service.text.d.ts +11 -3
  22. package/model/src/lib/notification/notification.task.service.d.ts +13 -1
  23. package/model/src/lib/notification/notification.task.service.handler.d.ts +27 -3
  24. package/model/src/lib/notification/notification.task.service.util.d.ts +16 -4
  25. package/model/src/lib/notification/notification.task.subtask.handler.d.ts +31 -1
  26. package/model/src/lib/notification/notification.util.d.ts +70 -0
  27. package/model/src/lib/storagefile/storagefile.action.init.service.d.ts +62 -1
  28. package/model/src/lib/storagefile/storagefile.action.server.d.ts +124 -2
  29. package/model/src/lib/storagefile/storagefile.error.d.ts +44 -0
  30. package/model/src/lib/storagefile/storagefile.module.d.ts +11 -0
  31. package/model/src/lib/storagefile/storagefile.task.service.handler.d.ts +4 -1
  32. package/model/src/lib/storagefile/storagefile.upload.service.d.ts +13 -1
  33. package/model/src/lib/storagefile/storagefile.upload.service.initializer.d.ts +43 -1
  34. package/model/src/lib/storagefile/storagefile.util.d.ts +8 -0
  35. package/oidc/index.cjs.default.js +1 -0
  36. package/oidc/index.cjs.js +5607 -0
  37. package/oidc/index.cjs.mjs +2 -0
  38. package/oidc/index.d.ts +1 -0
  39. package/oidc/index.esm.js +5560 -0
  40. package/oidc/package.json +26 -0
  41. package/oidc/src/index.d.ts +1 -0
  42. package/oidc/src/lib/controller/index.d.ts +3 -0
  43. package/oidc/src/lib/controller/oidc.interaction.controller.d.ts +54 -0
  44. package/oidc/src/lib/controller/oidc.provider.controller.d.ts +18 -0
  45. package/oidc/src/lib/controller/oidc.wellknown.controller.d.ts +36 -0
  46. package/oidc/src/lib/index.d.ts +6 -0
  47. package/oidc/src/lib/middleware/index.d.ts +3 -0
  48. package/oidc/src/lib/middleware/oauth-auth.decorator.d.ts +14 -0
  49. package/oidc/src/lib/middleware/oauth-auth.middleware.d.ts +21 -0
  50. package/oidc/src/lib/middleware/oauth-auth.module.d.ts +50 -0
  51. package/oidc/src/lib/model/index.d.ts +3 -0
  52. package/oidc/src/lib/model/jwks/index.d.ts +3 -0
  53. package/oidc/src/lib/model/jwks/jwks.d.ts +107 -0
  54. package/oidc/src/lib/model/jwks/jwks.id.d.ts +9 -0
  55. package/oidc/src/lib/model/jwks/jwks.query.d.ts +18 -0
  56. package/oidc/src/lib/model/model.d.ts +12 -0
  57. package/oidc/src/lib/model/oidc/index.d.ts +2 -0
  58. package/oidc/src/lib/model/oidc/oidcmodel.action.server.d.ts +62 -0
  59. package/oidc/src/lib/model/oidc/oidcmodel.module.d.ts +23 -0
  60. package/oidc/src/lib/oidc.config.d.ts +175 -0
  61. package/oidc/src/lib/oidc.module.d.ts +100 -0
  62. package/oidc/src/lib/service/index.d.ts +10 -0
  63. package/oidc/src/lib/service/oidc.account.d.ts +36 -0
  64. package/oidc/src/lib/service/oidc.account.service.d.ts +104 -0
  65. package/oidc/src/lib/service/oidc.adapter.service.d.ts +20 -0
  66. package/oidc/src/lib/service/oidc.auth.d.ts +26 -0
  67. package/oidc/src/lib/service/oidc.client.service.d.ts +57 -0
  68. package/oidc/src/lib/service/oidc.config.service.d.ts +100 -0
  69. package/oidc/src/lib/service/oidc.encryption.service.d.ts +53 -0
  70. package/oidc/src/lib/service/oidc.interaction.service.d.ts +44 -0
  71. package/oidc/src/lib/service/oidc.jwks.service.d.ts +105 -0
  72. package/oidc/src/lib/service/oidc.service.d.ts +55 -0
  73. package/package.json +21 -14
  74. package/src/lib/auth/auth.context.d.ts +22 -2
  75. package/src/lib/auth/auth.service.d.ts +5 -0
  76. package/src/lib/auth/auth.service.error.d.ts +2 -1
  77. package/src/lib/auth/auth.util.d.ts +15 -3
  78. package/src/lib/env/env.config.d.ts +42 -0
  79. package/src/lib/env/env.service.d.ts +17 -0
  80. package/src/lib/env/index.d.ts +1 -0
  81. package/src/lib/firestore/array.d.ts +11 -3
  82. package/src/lib/firestore/driver.accessor.batch.d.ts +27 -4
  83. package/src/lib/firestore/driver.accessor.d.ts +43 -0
  84. package/src/lib/firestore/driver.accessor.default.d.ts +20 -0
  85. package/src/lib/firestore/driver.accessor.transaction.d.ts +28 -4
  86. package/src/lib/firestore/driver.d.ts +14 -0
  87. package/src/lib/firestore/driver.query.d.ts +25 -0
  88. package/src/lib/firestore/increment.d.ts +13 -3
  89. package/src/lib/firestore/snapshot/index.d.ts +1 -1
  90. package/src/lib/firestore/snapshot/{snapshot.field.d.ts → snapshot.field.encrypt.d.ts} +13 -27
  91. package/src/lib/function/assert.d.ts +32 -16
  92. package/src/lib/function/context.d.ts +26 -0
  93. package/src/lib/function/error.auth.d.ts +15 -0
  94. package/src/lib/function/error.d.ts +68 -4
  95. package/src/lib/nest/app.d.ts +53 -9
  96. package/src/lib/nest/app.module.d.ts +90 -0
  97. package/src/lib/nest/auth/auth.module.d.ts +30 -4
  98. package/src/lib/nest/auth/auth.util.d.ts +38 -0
  99. package/src/lib/nest/controller/auth.context.server.d.ts +27 -0
  100. package/src/lib/nest/controller/index.d.ts +1 -0
  101. package/src/lib/nest/development/development.app.function.d.ts +45 -0
  102. package/src/lib/nest/development/development.assert.function.d.ts +19 -1
  103. package/src/lib/nest/development/development.function.d.ts +42 -3
  104. package/src/lib/nest/development/development.schedule.function.d.ts +29 -0
  105. package/src/lib/nest/development/development.schedule.function.error.d.ts +21 -0
  106. package/src/lib/nest/env/env.service.d.ts +9 -0
  107. package/src/lib/nest/env/env.util.d.ts +16 -0
  108. package/src/lib/nest/firebase/firebase.module.d.ts +13 -1
  109. package/src/lib/nest/firestore/firestore.module.d.ts +24 -8
  110. package/src/lib/nest/function/call.d.ts +75 -6
  111. package/src/lib/nest/function/context.d.ts +85 -2
  112. package/src/lib/nest/function/nest.d.ts +46 -0
  113. package/src/lib/nest/function/schedule.d.ts +49 -0
  114. package/src/lib/nest/function/v2/blocking.d.ts +92 -8
  115. package/src/lib/nest/function/v2/call.d.ts +38 -8
  116. package/src/lib/nest/function/v2/event.d.ts +67 -4
  117. package/src/lib/nest/function/v2/schedule.d.ts +36 -5
  118. package/src/lib/nest/index.d.ts +3 -0
  119. package/src/lib/nest/middleware/appcheck.d.ts +5 -0
  120. package/src/lib/nest/middleware/appcheck.middleware.d.ts +44 -14
  121. package/src/lib/nest/middleware/appcheck.module.d.ts +10 -1
  122. package/src/lib/nest/middleware/globalprefix.d.ts +31 -3
  123. package/src/lib/nest/middleware/index.d.ts +2 -1
  124. package/src/lib/nest/middleware/rawbody.middleware.d.ts +6 -0
  125. package/src/lib/nest/model/call.model.function.d.ts +69 -3
  126. package/src/lib/nest/model/create.model.function.d.ts +66 -0
  127. package/src/lib/nest/model/crud.assert.function.d.ts +27 -1
  128. package/src/lib/nest/model/delete.model.function.d.ts +55 -0
  129. package/src/lib/nest/model/permission.error.d.ts +15 -0
  130. package/src/lib/nest/model/read.model.function.d.ts +57 -0
  131. package/src/lib/nest/model/specifier.function.d.ts +58 -1
  132. package/src/lib/nest/model/update.model.function.d.ts +58 -0
  133. package/src/lib/nest/nest.provider.d.ts +24 -11
  134. package/src/lib/nest/nest.provider.server.d.ts +12 -0
  135. package/src/lib/nest/storage/storage.module.d.ts +30 -4
  136. package/src/lib/storage/driver.accessor.d.ts +33 -0
  137. package/src/lib/storage/driver.d.ts +14 -0
  138. package/src/lib/storage/storage.d.ts +11 -4
  139. package/src/lib/storage/storage.service.d.ts +10 -1
  140. package/src/lib/type.d.ts +7 -2
  141. package/test/index.cjs.js +4072 -757
  142. package/test/index.esm.js +4073 -761
  143. package/test/package.json +10 -10
  144. package/test/src/lib/firebase/firebase.admin.auth.d.ts +82 -1
  145. package/test/src/lib/firebase/firebase.admin.collection.d.ts +55 -3
  146. package/test/src/lib/firebase/firebase.admin.d.ts +64 -0
  147. package/test/src/lib/firebase/firebase.admin.function.d.ts +84 -0
  148. package/test/src/lib/firebase/firebase.admin.nest.d.ts +125 -17
  149. package/test/src/lib/firebase/firebase.admin.nest.function.callable.context.d.ts +44 -0
  150. package/test/src/lib/firebase/firebase.admin.nest.function.cloud.context.d.ts +41 -0
  151. package/test/src/lib/firebase/firebase.admin.nest.function.d.ts +98 -0
  152. package/test/src/lib/firebase/firebase.admin.test.server.d.ts +26 -0
  153. package/test/src/lib/firebase/firebase.d.ts +57 -2
  154. package/test/src/lib/firebase/firebase.function.d.ts +138 -0
  155. package/test/src/lib/firestore/firestore.admin.d.ts +6 -0
  156. package/test/src/lib/firestore/firestore.d.ts +30 -0
  157. package/test/src/lib/storage/storage.admin.d.ts +9 -3
  158. package/test/src/lib/storage/storage.d.ts +30 -0
  159. package/zoho/index.cjs.js +406 -73
  160. package/zoho/index.esm.js +406 -73
  161. package/zoho/package.json +8 -8
  162. package/zoho/src/lib/zoho.accounts.firebase.d.ts +13 -2
  163. package/zoho/src/lib/zoho.accounts.firebase.system.d.ts +29 -6
  164. package/index.cjs.js.map +0 -1
  165. package/index.esm.js.map +0 -1
  166. /package/src/lib/nest/middleware/{webhook.d.ts → webhook.module.d.ts} +0 -0
package/zoho/index.esm.js CHANGED
@@ -1,109 +1,442 @@
1
1
  import { firestoreSubObject, firestoreDate, firestoreNumber, firestoreString, firestoreObjectArray } from '@dereekb/firebase';
2
2
  import { isPast, filterUniqueFunction } from '@dereekb/util';
3
3
 
4
- const ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE = 'zoho_access_token';
5
- const zohoAccessTokenSystemStateEmbeddedTokenConverter = firestoreSubObject({
4
+ /**
5
+ * {@link SystemState} type identifier for storing Zoho access tokens in Firestore.
6
+ */ var ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE = 'zoho_access_token';
7
+ var zohoAccessTokenSystemStateEmbeddedTokenConverter = firestoreSubObject({
6
8
  objectField: {
7
9
  fields: {
8
10
  key: firestoreString(),
9
11
  accessToken: firestoreString(),
10
12
  scope: firestoreString(),
11
13
  apiDomain: firestoreString(),
12
- expiresIn: firestoreNumber({ default: 3600 }),
14
+ expiresIn: firestoreNumber({
15
+ default: 3600
16
+ }),
13
17
  expiresAt: firestoreDate()
14
18
  }
15
19
  }
16
20
  });
17
21
  /**
18
- * NOTE: Be sure to register this data converter with the SystemStateStoredDataConverterMap for your app.
19
- */
20
- const zohoAccessTokenSystemStateDataConverter = firestoreSubObject({
22
+ * Firestore field converter for {@link ZohoAccessTokenSystemStateData}.
23
+ *
24
+ * Automatically filters out expired tokens on read and enforces uniqueness by service key.
25
+ * Must be registered in the app's {@link SystemStateStoredDataConverterMap} under
26
+ * the {@link ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE} key.
27
+ */ var zohoAccessTokenSystemStateDataConverter = firestoreSubObject({
21
28
  objectField: {
22
29
  fields: {
23
30
  tokens: firestoreObjectArray({
24
31
  firestoreField: zohoAccessTokenSystemStateEmbeddedTokenConverter,
25
- filterUnique: filterUniqueFunction((x) => x.key), // only one token per key is allowed
26
- filter: (x) => (x?.expiresAt ? !isPast(x.expiresAt) : true) // filter out expired values or values that have no expiration
32
+ filterUnique: filterUniqueFunction(function(x) {
33
+ return x.key;
34
+ }),
35
+ filter: function filter(x) {
36
+ return (x === null || x === void 0 ? void 0 : x.expiresAt) ? !isPast(x.expiresAt) : true // filter out expired values or values that have no expiration
37
+ ;
38
+ }
27
39
  }),
28
- lat: firestoreDate({ saveDefaultAsNow: true })
40
+ lat: firestoreDate({
41
+ saveDefaultAsNow: true
42
+ })
29
43
  }
30
44
  }
31
45
  });
32
46
  /**
33
- * Convenience function for loading the document for ZohoAccessTokenSystemStateData.
47
+ * Loads the {@link SystemStateDocument} that stores {@link ZohoAccessTokenSystemStateData},
48
+ * using {@link ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE} as the document ID.
49
+ *
50
+ * @param accessor - the document accessor for the SystemState collection
34
51
  *
35
- * @param accessor
36
- * @returns
37
- */
38
- function loadZohoAccessTokenSystemState(accessor) {
52
+ * @example
53
+ * ```ts
54
+ * const doc = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessor());
55
+ * const data = await doc.snapshotData();
56
+ * ```
57
+ */ function loadZohoAccessTokenSystemState(accessor) {
39
58
  return accessor.loadDocumentForId(ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE);
40
59
  }
41
60
 
61
+ function _array_like_to_array(arr, len) {
62
+ if (len == null || len > arr.length) len = arr.length;
63
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
64
+ return arr2;
65
+ }
66
+ function _array_without_holes(arr) {
67
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
68
+ }
69
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
70
+ try {
71
+ var info = gen[key](arg);
72
+ var value = info.value;
73
+ } catch (error) {
74
+ reject(error);
75
+ return;
76
+ }
77
+ if (info.done) {
78
+ resolve(value);
79
+ } else {
80
+ Promise.resolve(value).then(_next, _throw);
81
+ }
82
+ }
83
+ function _async_to_generator(fn) {
84
+ return function() {
85
+ var self = this, args = arguments;
86
+ return new Promise(function(resolve, reject) {
87
+ var gen = fn.apply(self, args);
88
+ function _next(value) {
89
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
90
+ }
91
+ function _throw(err) {
92
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
93
+ }
94
+ _next(undefined);
95
+ });
96
+ };
97
+ }
98
+ function _define_property(obj, key, value) {
99
+ if (key in obj) {
100
+ Object.defineProperty(obj, key, {
101
+ value: value,
102
+ enumerable: true,
103
+ configurable: true,
104
+ writable: true
105
+ });
106
+ } else {
107
+ obj[key] = value;
108
+ }
109
+ return obj;
110
+ }
111
+ function _iterable_to_array(iter) {
112
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
113
+ }
114
+ function _non_iterable_spread() {
115
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
116
+ }
117
+ function _object_spread(target) {
118
+ for(var i = 1; i < arguments.length; i++){
119
+ var source = arguments[i] != null ? arguments[i] : {};
120
+ var ownKeys = Object.keys(source);
121
+ if (typeof Object.getOwnPropertySymbols === "function") {
122
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
123
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
124
+ }));
125
+ }
126
+ ownKeys.forEach(function(key) {
127
+ _define_property(target, key, source[key]);
128
+ });
129
+ }
130
+ return target;
131
+ }
132
+ function ownKeys(object, enumerableOnly) {
133
+ var keys = Object.keys(object);
134
+ if (Object.getOwnPropertySymbols) {
135
+ var symbols = Object.getOwnPropertySymbols(object);
136
+ keys.push.apply(keys, symbols);
137
+ }
138
+ return keys;
139
+ }
140
+ function _object_spread_props(target, source) {
141
+ source = source != null ? source : {};
142
+ if (Object.getOwnPropertyDescriptors) {
143
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
144
+ } else {
145
+ ownKeys(Object(source)).forEach(function(key) {
146
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
147
+ });
148
+ }
149
+ return target;
150
+ }
151
+ function _to_consumable_array(arr) {
152
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
153
+ }
154
+ function _unsupported_iterable_to_array(o, minLen) {
155
+ if (!o) return;
156
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
157
+ var n = Object.prototype.toString.call(o).slice(8, -1);
158
+ if (n === "Object" && o.constructor) n = o.constructor.name;
159
+ if (n === "Map" || n === "Set") return Array.from(n);
160
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
161
+ }
162
+ function _ts_generator(thisArg, body) {
163
+ var f, y, t, _ = {
164
+ label: 0,
165
+ sent: function() {
166
+ if (t[0] & 1) throw t[1];
167
+ return t[1];
168
+ },
169
+ trys: [],
170
+ ops: []
171
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
172
+ return d(g, "next", {
173
+ value: verb(0)
174
+ }), d(g, "throw", {
175
+ value: verb(1)
176
+ }), d(g, "return", {
177
+ value: verb(2)
178
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
179
+ value: function() {
180
+ return this;
181
+ }
182
+ }), g;
183
+ function verb(n) {
184
+ return function(v) {
185
+ return step([
186
+ n,
187
+ v
188
+ ]);
189
+ };
190
+ }
191
+ function step(op) {
192
+ if (f) throw new TypeError("Generator is already executing.");
193
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
194
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
195
+ if (y = 0, t) op = [
196
+ op[0] & 2,
197
+ t.value
198
+ ];
199
+ switch(op[0]){
200
+ case 0:
201
+ case 1:
202
+ t = op;
203
+ break;
204
+ case 4:
205
+ _.label++;
206
+ return {
207
+ value: op[1],
208
+ done: false
209
+ };
210
+ case 5:
211
+ _.label++;
212
+ y = op[1];
213
+ op = [
214
+ 0
215
+ ];
216
+ continue;
217
+ case 7:
218
+ op = _.ops.pop();
219
+ _.trys.pop();
220
+ continue;
221
+ default:
222
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
223
+ _ = 0;
224
+ continue;
225
+ }
226
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
227
+ _.label = op[1];
228
+ break;
229
+ }
230
+ if (op[0] === 6 && _.label < t[1]) {
231
+ _.label = t[1];
232
+ t = op;
233
+ break;
234
+ }
235
+ if (t && _.label < t[2]) {
236
+ _.label = t[2];
237
+ _.ops.push(op);
238
+ break;
239
+ }
240
+ if (t[2]) _.ops.pop();
241
+ _.trys.pop();
242
+ continue;
243
+ }
244
+ op = body.call(thisArg, _);
245
+ } catch (e) {
246
+ op = [
247
+ 6,
248
+ e
249
+ ];
250
+ y = 0;
251
+ } finally{
252
+ f = t = 0;
253
+ }
254
+ if (op[0] & 5) throw op[1];
255
+ return {
256
+ value: op[0] ? op[1] : void 0,
257
+ done: true
258
+ };
259
+ }
260
+ }
42
261
  /**
43
- * Creates a ZohoAccountsAccessTokenCacheService from the input SystemStateFirestoreCollection.
262
+ * Creates a {@link ZohoAccountsAccessTokenCacheService} backed by Firestore {@link SystemState} documents.
44
263
  *
45
- * @param collection
46
- */
47
- function firebaseZohoAccountsAccessTokenCacheService(systemStateCollection) {
48
- const systemStateDocumentAccessor = systemStateCollection.documentAccessor();
49
- const service = {
50
- loadZohoAccessTokenCache: function (serviceKey) {
51
- const cache = {
52
- loadCachedToken: async function () {
53
- const document = loadZohoAccessTokenSystemState(systemStateDocumentAccessor);
54
- const existingData = await document.snapshotData();
55
- let result = null;
56
- if (existingData != null) {
57
- const tokensArray = existingData?.data?.tokens ?? [];
58
- result = tokensArray.find((x) => x.key === serviceKey);
59
- }
60
- return result;
61
- },
62
- updateCachedToken: async function (accessToken) {
63
- // run in a transaction
64
- await systemStateCollection.firestoreContext.runTransaction(async (transaction) => {
65
- const documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
66
- const existingData = await documentInTransaction.snapshotData();
67
- const existingTokens = existingData?.data?.tokens ?? [];
68
- const tokens = [
69
- // filter any potential old token for this service key
70
- ...existingTokens.filter((x) => x.key !== serviceKey),
71
- // add the new token
72
- {
73
- ...accessToken,
74
- key: serviceKey
264
+ * Each Zoho service integration gets its own cached access token entry keyed by the service key.
265
+ * Tokens are stored in a single {@link SystemState} document (type {@link ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE})
266
+ * and token updates/clears use Firestore transactions for concurrency safety.
267
+ *
268
+ * @param systemStateCollection - the Firestore collection for system state documents
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * const cacheService = firebaseZohoAccountsAccessTokenCacheService(systemStateCollection);
273
+ * const cache = cacheService.loadZohoAccessTokenCache('my-zoho-service');
274
+ * const token = await cache.loadCachedToken();
275
+ * ```
276
+ */ function firebaseZohoAccountsAccessTokenCacheService(systemStateCollection) {
277
+ var systemStateDocumentAccessor = systemStateCollection.documentAccessor();
278
+ var service = {
279
+ loadZohoAccessTokenCache: function loadZohoAccessTokenCache(serviceKey) {
280
+ var cache = {
281
+ loadCachedToken: function loadCachedToken() {
282
+ return _async_to_generator(function() {
283
+ var document, existingData, result, _ref, _existingData_data, tokensArray;
284
+ return _ts_generator(this, function(_state) {
285
+ switch(_state.label){
286
+ case 0:
287
+ document = loadZohoAccessTokenSystemState(systemStateDocumentAccessor);
288
+ return [
289
+ 4,
290
+ document.snapshotData()
291
+ ];
292
+ case 1:
293
+ existingData = _state.sent();
294
+ result = null;
295
+ if (existingData != null) {
296
+ tokensArray = (_ref = existingData === null || existingData === void 0 ? void 0 : (_existingData_data = existingData.data) === null || _existingData_data === void 0 ? void 0 : _existingData_data.tokens) !== null && _ref !== void 0 ? _ref : [];
297
+ result = tokensArray.find(function(x) {
298
+ return x.key === serviceKey;
299
+ });
300
+ }
301
+ return [
302
+ 2,
303
+ result
304
+ ];
75
305
  }
76
- ];
77
- const templateOrUpdate = {
78
- data: {
79
- tokens,
80
- lat: new Date()
306
+ });
307
+ })();
308
+ },
309
+ updateCachedToken: function updateCachedToken(accessToken) {
310
+ return _async_to_generator(function() {
311
+ return _ts_generator(this, function(_state) {
312
+ switch(_state.label){
313
+ case 0:
314
+ // run in a transaction
315
+ return [
316
+ 4,
317
+ systemStateCollection.firestoreContext.runTransaction(function(transaction) {
318
+ return _async_to_generator(function() {
319
+ var _ref, _existingData_data, documentInTransaction, existingData, existingTokens, tokens, templateOrUpdate;
320
+ return _ts_generator(this, function(_state) {
321
+ switch(_state.label){
322
+ case 0:
323
+ documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
324
+ return [
325
+ 4,
326
+ documentInTransaction.snapshotData()
327
+ ];
328
+ case 1:
329
+ existingData = _state.sent();
330
+ existingTokens = (_ref = existingData === null || existingData === void 0 ? void 0 : (_existingData_data = existingData.data) === null || _existingData_data === void 0 ? void 0 : _existingData_data.tokens) !== null && _ref !== void 0 ? _ref : [];
331
+ tokens = // filter any potential old token for this service key
332
+ _to_consumable_array(existingTokens.filter(function(x) {
333
+ return x.key !== serviceKey;
334
+ })).concat([
335
+ // add the new token
336
+ _object_spread_props(_object_spread({}, accessToken), {
337
+ key: serviceKey
338
+ })
339
+ ]);
340
+ templateOrUpdate = {
341
+ data: {
342
+ tokens: tokens,
343
+ lat: new Date()
344
+ }
345
+ };
346
+ if (!!existingData) return [
347
+ 3,
348
+ 3
349
+ ];
350
+ return [
351
+ 4,
352
+ documentInTransaction.create(templateOrUpdate)
353
+ ];
354
+ case 2:
355
+ _state.sent();
356
+ return [
357
+ 3,
358
+ 5
359
+ ];
360
+ case 3:
361
+ return [
362
+ 4,
363
+ documentInTransaction.update(templateOrUpdate)
364
+ ];
365
+ case 4:
366
+ _state.sent();
367
+ _state.label = 5;
368
+ case 5:
369
+ return [
370
+ 2
371
+ ];
372
+ }
373
+ });
374
+ })();
375
+ })
376
+ ];
377
+ case 1:
378
+ _state.sent();
379
+ return [
380
+ 2
381
+ ];
81
382
  }
82
- };
83
- // create/update depending on the current document's existence
84
- if (!existingData) {
85
- await documentInTransaction.create(templateOrUpdate);
86
- }
87
- else {
88
- await documentInTransaction.update(templateOrUpdate);
89
- }
90
- });
383
+ });
384
+ })();
91
385
  },
92
- clearCachedToken: async function () {
93
- await systemStateCollection.firestoreContext.runTransaction(async (transaction) => {
94
- const documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
95
- const existingData = await documentInTransaction.snapshotData();
96
- const templateOrUpdate = {
97
- data: {
98
- tokens: [],
99
- lat: new Date()
386
+ clearCachedToken: function clearCachedToken() {
387
+ return _async_to_generator(function() {
388
+ return _ts_generator(this, function(_state) {
389
+ switch(_state.label){
390
+ case 0:
391
+ return [
392
+ 4,
393
+ systemStateCollection.firestoreContext.runTransaction(function(transaction) {
394
+ return _async_to_generator(function() {
395
+ var documentInTransaction, existingData, templateOrUpdate;
396
+ return _ts_generator(this, function(_state) {
397
+ switch(_state.label){
398
+ case 0:
399
+ documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
400
+ return [
401
+ 4,
402
+ documentInTransaction.snapshotData()
403
+ ];
404
+ case 1:
405
+ existingData = _state.sent();
406
+ templateOrUpdate = {
407
+ data: {
408
+ tokens: [],
409
+ lat: new Date()
410
+ }
411
+ };
412
+ if (!existingData) return [
413
+ 3,
414
+ 3
415
+ ];
416
+ return [
417
+ 4,
418
+ documentInTransaction.update(templateOrUpdate)
419
+ ];
420
+ case 2:
421
+ _state.sent();
422
+ _state.label = 3;
423
+ case 3:
424
+ return [
425
+ 2
426
+ ];
427
+ }
428
+ });
429
+ })();
430
+ })
431
+ ];
432
+ case 1:
433
+ _state.sent();
434
+ return [
435
+ 2
436
+ ];
100
437
  }
101
- };
102
- // clear the tokens
103
- if (existingData) {
104
- await documentInTransaction.update(templateOrUpdate);
105
- }
106
- });
438
+ });
439
+ })();
107
440
  }
108
441
  };
109
442
  return cache;
package/zoho/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@dereekb/firebase-server/zoho",
3
- "version": "13.2.2",
3
+ "version": "13.3.1",
4
4
  "peerDependencies": {
5
- "@dereekb/date": "13.2.2",
6
- "@dereekb/model": "13.2.2",
7
- "@dereekb/nestjs": "13.2.2",
8
- "@dereekb/rxjs": "13.2.2",
9
- "@dereekb/firebase": "13.2.2",
10
- "@dereekb/util": "13.2.2",
11
- "@dereekb/zoho": "13.2.2"
5
+ "@dereekb/date": "13.3.1",
6
+ "@dereekb/model": "13.3.1",
7
+ "@dereekb/nestjs": "13.3.1",
8
+ "@dereekb/rxjs": "13.3.1",
9
+ "@dereekb/firebase": "13.3.1",
10
+ "@dereekb/util": "13.3.1",
11
+ "@dereekb/zoho": "13.3.1"
12
12
  },
13
13
  "exports": {
14
14
  "./package.json": "./package.json",
@@ -1,8 +1,19 @@
1
1
  import { type SystemStateFirestoreCollection } from '@dereekb/firebase';
2
2
  import { type ZohoAccountsAccessTokenCacheService } from '@dereekb/zoho/nestjs';
3
3
  /**
4
- * Creates a ZohoAccountsAccessTokenCacheService from the input SystemStateFirestoreCollection.
4
+ * Creates a {@link ZohoAccountsAccessTokenCacheService} backed by Firestore {@link SystemState} documents.
5
5
  *
6
- * @param collection
6
+ * Each Zoho service integration gets its own cached access token entry keyed by the service key.
7
+ * Tokens are stored in a single {@link SystemState} document (type {@link ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE})
8
+ * and token updates/clears use Firestore transactions for concurrency safety.
9
+ *
10
+ * @param systemStateCollection - the Firestore collection for system state documents
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const cacheService = firebaseZohoAccountsAccessTokenCacheService(systemStateCollection);
15
+ * const cache = cacheService.loadZohoAccessTokenCache('my-zoho-service');
16
+ * const token = await cache.loadCachedToken();
17
+ * ```
7
18
  */
8
19
  export declare function firebaseZohoAccountsAccessTokenCacheService(systemStateCollection: SystemStateFirestoreCollection): ZohoAccountsAccessTokenCacheService;
@@ -1,7 +1,14 @@
1
1
  import { type ZohoAccessToken, type ZohoServiceAccessTokenKey } from '@dereekb/zoho';
2
2
  import { type FirestoreDocumentAccessor, type SystemState, type SystemStateDocument, type SystemStateStoredData, type SystemStateStoredDataFieldConverterConfig } from '@dereekb/firebase';
3
3
  import { type Configurable } from '@dereekb/util';
4
+ /**
5
+ * {@link SystemState} type identifier for storing Zoho access tokens in Firestore.
6
+ */
4
7
  export declare const ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE = "zoho_access_token";
8
+ /**
9
+ * Represents a single Zoho access token stored within the {@link SystemState} document,
10
+ * keyed by the service access token key to support multiple Zoho service integrations.
11
+ */
5
12
  export interface ZohoAccessTokenSystemStateEmbeddedToken extends Configurable<ZohoAccessToken> {
6
13
  /**
7
14
  * The access token key
@@ -9,24 +16,40 @@ export interface ZohoAccessTokenSystemStateEmbeddedToken extends Configurable<Zo
9
16
  key: ZohoServiceAccessTokenKey;
10
17
  }
11
18
  export declare const zohoAccessTokenSystemStateEmbeddedTokenConverter: import("@dereekb/firebase").FirestoreSubObjectFieldMapFunctionsConfig<ZohoAccessTokenSystemStateEmbeddedToken, Partial<import("@dereekb/util").ReplaceType<ZohoAccessTokenSystemStateEmbeddedToken, import("@dereekb/util").MaybeMap<object>, any>>>;
19
+ /**
20
+ * Data shape stored within a {@link SystemState} document for caching multiple Zoho access tokens.
21
+ *
22
+ * Expired tokens are automatically filtered out during Firestore read via the converter,
23
+ * and only one token per service key is retained (enforced by {@link filterUniqueFunction}).
24
+ */
12
25
  export interface ZohoAccessTokenSystemStateData extends SystemStateStoredData {
13
26
  /**
14
- * The array of access tokens
27
+ * The array of cached access tokens, one per Zoho service integration.
15
28
  */
16
29
  tokens: ZohoAccessTokenSystemStateEmbeddedToken[];
17
30
  /**
18
- * Last updated at
31
+ * Timestamp of the last token update.
19
32
  */
20
33
  lat: Date;
21
34
  }
22
35
  /**
23
- * NOTE: Be sure to register this data converter with the SystemStateStoredDataConverterMap for your app.
36
+ * Firestore field converter for {@link ZohoAccessTokenSystemStateData}.
37
+ *
38
+ * Automatically filters out expired tokens on read and enforces uniqueness by service key.
39
+ * Must be registered in the app's {@link SystemStateStoredDataConverterMap} under
40
+ * the {@link ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE} key.
24
41
  */
25
42
  export declare const zohoAccessTokenSystemStateDataConverter: SystemStateStoredDataFieldConverterConfig<ZohoAccessTokenSystemStateData>;
26
43
  /**
27
- * Convenience function for loading the document for ZohoAccessTokenSystemStateData.
44
+ * Loads the {@link SystemStateDocument} that stores {@link ZohoAccessTokenSystemStateData},
45
+ * using {@link ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE} as the document ID.
46
+ *
47
+ * @param accessor - the document accessor for the SystemState collection
28
48
  *
29
- * @param accessor
30
- * @returns
49
+ * @example
50
+ * ```ts
51
+ * const doc = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessor());
52
+ * const data = await doc.snapshotData();
53
+ * ```
31
54
  */
32
55
  export declare function loadZohoAccessTokenSystemState(accessor: FirestoreDocumentAccessor<SystemState<SystemStateStoredData>, SystemStateDocument<SystemStateStoredData>>): SystemStateDocument<ZohoAccessTokenSystemStateData>;