@dereekb/firebase-server 13.2.1 → 13.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +7506 -1884
- package/index.esm.js +7505 -1890
- package/mailgun/index.cjs.js +333 -31
- package/mailgun/index.esm.js +333 -31
- package/mailgun/package.json +8 -8
- package/mailgun/src/lib/auth.mailgun.d.ts +22 -3
- package/model/index.cjs.js +11334 -3830
- package/model/index.esm.js +11338 -3834
- package/model/package.json +8 -8
- package/model/src/lib/mailgun/notification.send.service.mailgun.d.ts +27 -1
- package/model/src/lib/notification/notification.action.init.service.d.ts +93 -1
- package/model/src/lib/notification/notification.action.service.d.ts +151 -2
- package/model/src/lib/notification/notification.config.d.ts +19 -7
- package/model/src/lib/notification/notification.config.service.d.ts +44 -6
- package/model/src/lib/notification/notification.create.run.d.ts +33 -5
- package/model/src/lib/notification/notification.error.d.ts +63 -0
- package/model/src/lib/notification/notification.module.d.ts +11 -0
- package/model/src/lib/notification/notification.send.d.ts +8 -1
- package/model/src/lib/notification/notification.send.service.d.ts +7 -1
- package/model/src/lib/notification/notification.send.service.notificationsummary.d.ts +32 -2
- package/model/src/lib/notification/notification.send.service.text.d.ts +11 -3
- package/model/src/lib/notification/notification.task.service.d.ts +13 -1
- package/model/src/lib/notification/notification.task.service.handler.d.ts +27 -3
- package/model/src/lib/notification/notification.task.service.util.d.ts +16 -4
- package/model/src/lib/notification/notification.task.subtask.handler.d.ts +31 -1
- package/model/src/lib/notification/notification.util.d.ts +70 -0
- package/model/src/lib/storagefile/storagefile.action.init.service.d.ts +62 -1
- package/model/src/lib/storagefile/storagefile.action.server.d.ts +124 -2
- package/model/src/lib/storagefile/storagefile.error.d.ts +44 -0
- package/model/src/lib/storagefile/storagefile.module.d.ts +11 -0
- package/model/src/lib/storagefile/storagefile.task.service.handler.d.ts +4 -1
- package/model/src/lib/storagefile/storagefile.upload.service.d.ts +13 -1
- package/model/src/lib/storagefile/storagefile.upload.service.initializer.d.ts +43 -1
- package/model/src/lib/storagefile/storagefile.util.d.ts +8 -0
- package/oidc/index.cjs.default.js +1 -0
- package/oidc/index.cjs.js +5607 -0
- package/oidc/index.cjs.mjs +2 -0
- package/oidc/index.d.ts +1 -0
- package/oidc/index.esm.js +5560 -0
- package/oidc/package.json +26 -0
- package/oidc/src/index.d.ts +1 -0
- package/oidc/src/lib/controller/index.d.ts +3 -0
- package/oidc/src/lib/controller/oidc.interaction.controller.d.ts +54 -0
- package/oidc/src/lib/controller/oidc.provider.controller.d.ts +18 -0
- package/oidc/src/lib/controller/oidc.wellknown.controller.d.ts +36 -0
- package/oidc/src/lib/index.d.ts +6 -0
- package/oidc/src/lib/middleware/index.d.ts +3 -0
- package/oidc/src/lib/middleware/oauth-auth.decorator.d.ts +14 -0
- package/oidc/src/lib/middleware/oauth-auth.middleware.d.ts +21 -0
- package/oidc/src/lib/middleware/oauth-auth.module.d.ts +50 -0
- package/oidc/src/lib/model/index.d.ts +3 -0
- package/oidc/src/lib/model/jwks/index.d.ts +3 -0
- package/oidc/src/lib/model/jwks/jwks.d.ts +107 -0
- package/oidc/src/lib/model/jwks/jwks.id.d.ts +9 -0
- package/oidc/src/lib/model/jwks/jwks.query.d.ts +18 -0
- package/oidc/src/lib/model/model.d.ts +12 -0
- package/oidc/src/lib/model/oidc/index.d.ts +2 -0
- package/oidc/src/lib/model/oidc/oidcmodel.action.server.d.ts +62 -0
- package/oidc/src/lib/model/oidc/oidcmodel.module.d.ts +23 -0
- package/oidc/src/lib/oidc.config.d.ts +175 -0
- package/oidc/src/lib/oidc.module.d.ts +100 -0
- package/oidc/src/lib/service/index.d.ts +10 -0
- package/oidc/src/lib/service/oidc.account.d.ts +36 -0
- package/oidc/src/lib/service/oidc.account.service.d.ts +104 -0
- package/oidc/src/lib/service/oidc.adapter.service.d.ts +20 -0
- package/oidc/src/lib/service/oidc.auth.d.ts +26 -0
- package/oidc/src/lib/service/oidc.client.service.d.ts +57 -0
- package/oidc/src/lib/service/oidc.config.service.d.ts +100 -0
- package/oidc/src/lib/service/oidc.encryption.service.d.ts +53 -0
- package/oidc/src/lib/service/oidc.interaction.service.d.ts +44 -0
- package/oidc/src/lib/service/oidc.jwks.service.d.ts +105 -0
- package/oidc/src/lib/service/oidc.service.d.ts +55 -0
- package/package.json +15 -9
- package/src/lib/auth/auth.context.d.ts +22 -2
- package/src/lib/auth/auth.service.d.ts +5 -0
- package/src/lib/auth/auth.service.error.d.ts +2 -1
- package/src/lib/auth/auth.util.d.ts +15 -3
- package/src/lib/env/env.config.d.ts +42 -0
- package/src/lib/env/env.service.d.ts +17 -0
- package/src/lib/env/index.d.ts +1 -0
- package/src/lib/firestore/array.d.ts +11 -3
- package/src/lib/firestore/driver.accessor.batch.d.ts +27 -4
- package/src/lib/firestore/driver.accessor.d.ts +43 -0
- package/src/lib/firestore/driver.accessor.default.d.ts +20 -0
- package/src/lib/firestore/driver.accessor.transaction.d.ts +28 -4
- package/src/lib/firestore/driver.d.ts +14 -0
- package/src/lib/firestore/driver.query.d.ts +25 -0
- package/src/lib/firestore/increment.d.ts +13 -3
- package/src/lib/firestore/snapshot/index.d.ts +1 -1
- package/src/lib/firestore/snapshot/{snapshot.field.d.ts → snapshot.field.encrypt.d.ts} +13 -27
- package/src/lib/function/assert.d.ts +32 -16
- package/src/lib/function/context.d.ts +26 -0
- package/src/lib/function/error.auth.d.ts +15 -0
- package/src/lib/function/error.d.ts +68 -4
- package/src/lib/nest/app.d.ts +53 -9
- package/src/lib/nest/app.module.d.ts +90 -0
- package/src/lib/nest/auth/auth.module.d.ts +30 -4
- package/src/lib/nest/auth/auth.util.d.ts +38 -0
- package/src/lib/nest/controller/auth.context.server.d.ts +27 -0
- package/src/lib/nest/controller/index.d.ts +1 -0
- package/src/lib/nest/development/development.app.function.d.ts +45 -0
- package/src/lib/nest/development/development.assert.function.d.ts +19 -1
- package/src/lib/nest/development/development.function.d.ts +42 -3
- package/src/lib/nest/development/development.schedule.function.d.ts +29 -0
- package/src/lib/nest/development/development.schedule.function.error.d.ts +21 -0
- package/src/lib/nest/env/env.service.d.ts +9 -0
- package/src/lib/nest/env/env.util.d.ts +16 -0
- package/src/lib/nest/firebase/firebase.module.d.ts +13 -1
- package/src/lib/nest/firestore/firestore.module.d.ts +24 -8
- package/src/lib/nest/function/call.d.ts +75 -6
- package/src/lib/nest/function/context.d.ts +85 -2
- package/src/lib/nest/function/nest.d.ts +46 -0
- package/src/lib/nest/function/schedule.d.ts +49 -0
- package/src/lib/nest/function/v2/blocking.d.ts +92 -8
- package/src/lib/nest/function/v2/call.d.ts +38 -8
- package/src/lib/nest/function/v2/event.d.ts +67 -4
- package/src/lib/nest/function/v2/schedule.d.ts +36 -5
- package/src/lib/nest/index.d.ts +3 -0
- package/src/lib/nest/middleware/appcheck.d.ts +5 -0
- package/src/lib/nest/middleware/appcheck.middleware.d.ts +44 -14
- package/src/lib/nest/middleware/appcheck.module.d.ts +10 -1
- package/src/lib/nest/middleware/globalprefix.d.ts +31 -3
- package/src/lib/nest/middleware/index.d.ts +2 -1
- package/src/lib/nest/middleware/rawbody.middleware.d.ts +6 -0
- package/src/lib/nest/model/call.model.function.d.ts +69 -3
- package/src/lib/nest/model/create.model.function.d.ts +66 -0
- package/src/lib/nest/model/crud.assert.function.d.ts +27 -1
- package/src/lib/nest/model/delete.model.function.d.ts +55 -0
- package/src/lib/nest/model/permission.error.d.ts +15 -0
- package/src/lib/nest/model/read.model.function.d.ts +57 -0
- package/src/lib/nest/model/specifier.function.d.ts +58 -1
- package/src/lib/nest/model/update.model.function.d.ts +58 -0
- package/src/lib/nest/nest.provider.d.ts +24 -11
- package/src/lib/nest/nest.provider.server.d.ts +12 -0
- package/src/lib/nest/storage/storage.module.d.ts +30 -4
- package/src/lib/storage/driver.accessor.d.ts +33 -0
- package/src/lib/storage/driver.d.ts +14 -0
- package/src/lib/storage/storage.d.ts +11 -4
- package/src/lib/storage/storage.service.d.ts +10 -1
- package/src/lib/type.d.ts +7 -2
- package/test/index.cjs.js +4072 -757
- package/test/index.esm.js +4073 -761
- package/test/package.json +8 -8
- package/test/src/lib/firebase/firebase.admin.auth.d.ts +82 -1
- package/test/src/lib/firebase/firebase.admin.collection.d.ts +55 -3
- package/test/src/lib/firebase/firebase.admin.d.ts +64 -0
- package/test/src/lib/firebase/firebase.admin.function.d.ts +84 -0
- package/test/src/lib/firebase/firebase.admin.nest.d.ts +125 -17
- package/test/src/lib/firebase/firebase.admin.nest.function.callable.context.d.ts +44 -0
- package/test/src/lib/firebase/firebase.admin.nest.function.cloud.context.d.ts +41 -0
- package/test/src/lib/firebase/firebase.admin.nest.function.d.ts +98 -0
- package/test/src/lib/firebase/firebase.admin.test.server.d.ts +26 -0
- package/test/src/lib/firebase/firebase.d.ts +57 -2
- package/test/src/lib/firebase/firebase.function.d.ts +138 -0
- package/test/src/lib/firestore/firestore.admin.d.ts +6 -0
- package/test/src/lib/firestore/firestore.d.ts +30 -0
- package/test/src/lib/storage/storage.admin.d.ts +9 -3
- package/test/src/lib/storage/storage.d.ts +30 -0
- package/zoho/index.cjs.js +406 -73
- package/zoho/index.esm.js +406 -73
- package/zoho/package.json +8 -8
- package/zoho/src/lib/zoho.accounts.firebase.d.ts +13 -2
- package/zoho/src/lib/zoho.accounts.firebase.system.d.ts +29 -6
- package/index.cjs.js.map +0 -1
- package/index.esm.js.map +0 -1
- /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
|
-
|
|
5
|
-
|
|
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({
|
|
14
|
+
expiresIn: firestoreNumber({
|
|
15
|
+
default: 3600
|
|
16
|
+
}),
|
|
13
17
|
expiresAt: firestoreDate()
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
});
|
|
17
21
|
/**
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
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)
|
|
26
|
-
|
|
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({
|
|
40
|
+
lat: firestoreDate({
|
|
41
|
+
saveDefaultAsNow: true
|
|
42
|
+
})
|
|
29
43
|
}
|
|
30
44
|
}
|
|
31
45
|
});
|
|
32
46
|
/**
|
|
33
|
-
*
|
|
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
|
-
* @
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
262
|
+
* Creates a {@link ZohoAccountsAccessTokenCacheService} backed by Firestore {@link SystemState} documents.
|
|
44
263
|
*
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
84
|
-
if (!existingData) {
|
|
85
|
-
await documentInTransaction.create(templateOrUpdate);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
await documentInTransaction.update(templateOrUpdate);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
383
|
+
});
|
|
384
|
+
})();
|
|
91
385
|
},
|
|
92
|
-
clearCachedToken:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "13.3.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@dereekb/date": "13.
|
|
6
|
-
"@dereekb/model": "13.
|
|
7
|
-
"@dereekb/nestjs": "13.
|
|
8
|
-
"@dereekb/rxjs": "13.
|
|
9
|
-
"@dereekb/firebase": "13.
|
|
10
|
-
"@dereekb/util": "13.
|
|
11
|
-
"@dereekb/zoho": "13.
|
|
5
|
+
"@dereekb/date": "13.3.0",
|
|
6
|
+
"@dereekb/model": "13.3.0",
|
|
7
|
+
"@dereekb/nestjs": "13.3.0",
|
|
8
|
+
"@dereekb/rxjs": "13.3.0",
|
|
9
|
+
"@dereekb/firebase": "13.3.0",
|
|
10
|
+
"@dereekb/util": "13.3.0",
|
|
11
|
+
"@dereekb/zoho": "13.3.0"
|
|
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
|
|
4
|
+
* Creates a {@link ZohoAccountsAccessTokenCacheService} backed by Firestore {@link SystemState} documents.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
31
|
+
* Timestamp of the last token update.
|
|
19
32
|
*/
|
|
20
33
|
lat: Date;
|
|
21
34
|
}
|
|
22
35
|
/**
|
|
23
|
-
*
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
30
|
-
*
|
|
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>;
|