@dereekb/firebase-server 13.0.0 → 13.0.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.
package/test/package.json CHANGED
@@ -1,38 +1,34 @@
1
1
  {
2
2
  "name": "@dereekb/firebase-server/test",
3
- "version": "13.0.0",
4
- "types": "./src/index.d.ts",
5
- "module": "./index.esm.js",
6
- "main": "./index.cjs.js",
7
- "exports": {
8
- ".": {
9
- "types": "./src/index.d.ts",
10
- "node": {
11
- "require": "./index.cjs.js"
12
- },
13
- "browser": {
14
- "require": "./index.cjs.js",
15
- "import": "./index.esm.js"
16
- },
17
- "default": "./index.cjs.js"
18
- }
19
- },
3
+ "version": "13.0.2",
20
4
  "peerDependencies": {
21
- "@dereekb/date": "13.0.0",
22
- "@dereekb/rxjs": "13.0.0",
23
- "@dereekb/model": "13.0.0",
24
- "@dereekb/firebase": "13.0.0",
25
- "@dereekb/firebase-server": "13.0.0",
26
- "@dereekb/nestjs": "13.0.0",
27
- "@dereekb/util": "13.0.0",
5
+ "@dereekb/date": "13.0.2",
6
+ "@dereekb/firebase": "13.0.2",
7
+ "@dereekb/firebase-server": "13.0.2",
8
+ "@dereekb/model": "13.0.2",
9
+ "@dereekb/nestjs": "13.0.2",
10
+ "@dereekb/rxjs": "13.0.2",
11
+ "@dereekb/util": "13.0.2",
28
12
  "@google-cloud/firestore": "^7.0.0",
29
13
  "@google-cloud/storage": "^7.0.0",
14
+ "@nestjs/common": "^11.0.0",
30
15
  "@nestjs/testing": "^11.0.0",
31
16
  "firebase-admin": "^13.0.0",
32
17
  "firebase-functions": "^7.0.0",
33
18
  "firebase-functions-test": "3.4.1",
34
- "core-js": "^3.0.0",
35
19
  "jsonwebtoken": "^9.0.0",
36
20
  "make-error": "^1.3.0"
37
- }
21
+ },
22
+ "exports": {
23
+ "./package.json": "./package.json",
24
+ ".": {
25
+ "module": "./index.esm.js",
26
+ "types": "./index.d.ts",
27
+ "import": "./index.cjs.mjs",
28
+ "default": "./index.cjs.js"
29
+ }
30
+ },
31
+ "module": "./index.esm.js",
32
+ "main": "./index.cjs.js",
33
+ "types": "./index.d.ts"
38
34
  }
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;
package/zoho/index.cjs.js CHANGED
@@ -5,36 +5,31 @@ var util = require('@dereekb/util');
5
5
 
6
6
  const ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE = 'zoho_access_token';
7
7
  const zohoAccessTokenSystemStateEmbeddedTokenConverter = firebase.firestoreSubObject({
8
- objectField: {
9
- fields: {
10
- key: firebase.firestoreString(),
11
- accessToken: firebase.firestoreString(),
12
- scope: firebase.firestoreString(),
13
- apiDomain: firebase.firestoreString(),
14
- expiresIn: firebase.firestoreNumber({
15
- default: 3600
16
- }),
17
- expiresAt: firebase.firestoreDate()
8
+ objectField: {
9
+ fields: {
10
+ key: firebase.firestoreString(),
11
+ accessToken: firebase.firestoreString(),
12
+ scope: firebase.firestoreString(),
13
+ apiDomain: firebase.firestoreString(),
14
+ expiresIn: firebase.firestoreNumber({ default: 3600 }),
15
+ expiresAt: firebase.firestoreDate()
16
+ }
18
17
  }
19
- }
20
18
  });
21
19
  /**
22
20
  * NOTE: Be sure to register this data converter with the SystemStateStoredDataConverterMap for your app.
23
21
  */
24
22
  const zohoAccessTokenSystemStateDataConverter = firebase.firestoreSubObject({
25
- objectField: {
26
- fields: {
27
- tokens: firebase.firestoreObjectArray({
28
- firestoreField: zohoAccessTokenSystemStateEmbeddedTokenConverter,
29
- filterUnique: util.filterUniqueFunction(x => x.key),
30
- // only one token per key is allowed
31
- filter: x => x?.expiresAt ? !util.isPast(x.expiresAt) : true // filter out expired values or values that have no expiration
32
- }),
33
- lat: firebase.firestoreDate({
34
- saveDefaultAsNow: true
35
- })
23
+ objectField: {
24
+ fields: {
25
+ tokens: firebase.firestoreObjectArray({
26
+ firestoreField: zohoAccessTokenSystemStateEmbeddedTokenConverter,
27
+ filterUnique: util.filterUniqueFunction((x) => x.key), // only one token per key is allowed
28
+ filter: (x) => (x?.expiresAt ? !util.isPast(x.expiresAt) : true) // filter out expired values or values that have no expiration
29
+ }),
30
+ lat: firebase.firestoreDate({ saveDefaultAsNow: true })
31
+ }
36
32
  }
37
- }
38
33
  });
39
34
  /**
40
35
  * Convenience function for loading the document for ZohoAccessTokenSystemStateData.
@@ -43,7 +38,7 @@ const zohoAccessTokenSystemStateDataConverter = firebase.firestoreSubObject({
43
38
  * @returns
44
39
  */
45
40
  function loadZohoAccessTokenSystemState(accessor) {
46
- return accessor.loadDocumentForId(ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE);
41
+ return accessor.loadDocumentForId(ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE);
47
42
  }
48
43
 
49
44
  /**
@@ -52,69 +47,71 @@ function loadZohoAccessTokenSystemState(accessor) {
52
47
  * @param collection
53
48
  */
54
49
  function firebaseZohoAccountsAccessTokenCacheService(systemStateCollection) {
55
- const systemStateDocumentAccessor = systemStateCollection.documentAccessor();
56
- const service = {
57
- loadZohoAccessTokenCache: function (serviceKey) {
58
- const cache = {
59
- loadCachedToken: async function () {
60
- const document = loadZohoAccessTokenSystemState(systemStateDocumentAccessor);
61
- const existingData = await document.snapshotData();
62
- let result = null;
63
- if (existingData != null) {
64
- const tokensArray = existingData?.data?.tokens ?? [];
65
- result = tokensArray.find(x => x.key === serviceKey);
66
- }
67
- return result;
68
- },
69
- updateCachedToken: async function (accessToken) {
70
- // run in a transaction
71
- await systemStateCollection.firestoreContext.runTransaction(async transaction => {
72
- const documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
73
- const existingData = await documentInTransaction.snapshotData();
74
- const existingTokens = existingData?.data?.tokens ?? [];
75
- const tokens = [
76
- // filter any potential old token for this service key
77
- ...existingTokens.filter(x => x.key !== serviceKey),
78
- // add the new token
79
- {
80
- ...accessToken,
81
- key: serviceKey
82
- }];
83
- const templateOrUpdate = {
84
- data: {
85
- tokens,
86
- lat: new Date()
87
- }
50
+ const systemStateDocumentAccessor = systemStateCollection.documentAccessor();
51
+ const service = {
52
+ loadZohoAccessTokenCache: function (serviceKey) {
53
+ const cache = {
54
+ loadCachedToken: async function () {
55
+ const document = loadZohoAccessTokenSystemState(systemStateDocumentAccessor);
56
+ const existingData = await document.snapshotData();
57
+ let result = null;
58
+ if (existingData != null) {
59
+ const tokensArray = existingData?.data?.tokens ?? [];
60
+ result = tokensArray.find((x) => x.key === serviceKey);
61
+ }
62
+ return result;
63
+ },
64
+ updateCachedToken: async function (accessToken) {
65
+ // run in a transaction
66
+ await systemStateCollection.firestoreContext.runTransaction(async (transaction) => {
67
+ const documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
68
+ const existingData = await documentInTransaction.snapshotData();
69
+ const existingTokens = existingData?.data?.tokens ?? [];
70
+ const tokens = [
71
+ // filter any potential old token for this service key
72
+ ...existingTokens.filter((x) => x.key !== serviceKey),
73
+ // add the new token
74
+ {
75
+ ...accessToken,
76
+ key: serviceKey
77
+ }
78
+ ];
79
+ const templateOrUpdate = {
80
+ data: {
81
+ tokens,
82
+ lat: new Date()
83
+ }
84
+ };
85
+ // create/update depending on the current document's existence
86
+ if (!existingData) {
87
+ await documentInTransaction.create(templateOrUpdate);
88
+ }
89
+ else {
90
+ await documentInTransaction.update(templateOrUpdate);
91
+ }
92
+ });
93
+ },
94
+ clearCachedToken: async function () {
95
+ await systemStateCollection.firestoreContext.runTransaction(async (transaction) => {
96
+ const documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
97
+ const existingData = await documentInTransaction.snapshotData();
98
+ const templateOrUpdate = {
99
+ data: {
100
+ tokens: [],
101
+ lat: new Date()
102
+ }
103
+ };
104
+ // clear the tokens
105
+ if (existingData) {
106
+ await documentInTransaction.update(templateOrUpdate);
107
+ }
108
+ });
109
+ }
88
110
  };
89
- // create/update depending on the current document's existence
90
- if (!existingData) {
91
- await documentInTransaction.create(templateOrUpdate);
92
- } else {
93
- await documentInTransaction.update(templateOrUpdate);
94
- }
95
- });
96
- },
97
- clearCachedToken: async function () {
98
- await systemStateCollection.firestoreContext.runTransaction(async transaction => {
99
- const documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
100
- const existingData = await documentInTransaction.snapshotData();
101
- const templateOrUpdate = {
102
- data: {
103
- tokens: [],
104
- lat: new Date()
105
- }
106
- };
107
- // clear the tokens
108
- if (existingData) {
109
- await documentInTransaction.update(templateOrUpdate);
110
- }
111
- });
111
+ return cache;
112
112
  }
113
- };
114
- return cache;
115
- }
116
- };
117
- return service;
113
+ };
114
+ return service;
118
115
  }
119
116
 
120
117
  exports.ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE = ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE;
@@ -0,0 +1,2 @@
1
+ export * from './index.cjs.js';
2
+ export { _default as default } from './index.cjs.default.js';
package/zoho/index.esm.js CHANGED
@@ -3,36 +3,31 @@ import { isPast, filterUniqueFunction } from '@dereekb/util';
3
3
 
4
4
  const ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE = 'zoho_access_token';
5
5
  const zohoAccessTokenSystemStateEmbeddedTokenConverter = firestoreSubObject({
6
- objectField: {
7
- fields: {
8
- key: firestoreString(),
9
- accessToken: firestoreString(),
10
- scope: firestoreString(),
11
- apiDomain: firestoreString(),
12
- expiresIn: firestoreNumber({
13
- default: 3600
14
- }),
15
- expiresAt: firestoreDate()
6
+ objectField: {
7
+ fields: {
8
+ key: firestoreString(),
9
+ accessToken: firestoreString(),
10
+ scope: firestoreString(),
11
+ apiDomain: firestoreString(),
12
+ expiresIn: firestoreNumber({ default: 3600 }),
13
+ expiresAt: firestoreDate()
14
+ }
16
15
  }
17
- }
18
16
  });
19
17
  /**
20
18
  * NOTE: Be sure to register this data converter with the SystemStateStoredDataConverterMap for your app.
21
19
  */
22
20
  const zohoAccessTokenSystemStateDataConverter = firestoreSubObject({
23
- objectField: {
24
- fields: {
25
- tokens: firestoreObjectArray({
26
- firestoreField: zohoAccessTokenSystemStateEmbeddedTokenConverter,
27
- filterUnique: filterUniqueFunction(x => x.key),
28
- // only one token per key is allowed
29
- filter: x => x?.expiresAt ? !isPast(x.expiresAt) : true // filter out expired values or values that have no expiration
30
- }),
31
- lat: firestoreDate({
32
- saveDefaultAsNow: true
33
- })
21
+ objectField: {
22
+ fields: {
23
+ tokens: firestoreObjectArray({
24
+ 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
27
+ }),
28
+ lat: firestoreDate({ saveDefaultAsNow: true })
29
+ }
34
30
  }
35
- }
36
31
  });
37
32
  /**
38
33
  * Convenience function for loading the document for ZohoAccessTokenSystemStateData.
@@ -41,7 +36,7 @@ const zohoAccessTokenSystemStateDataConverter = firestoreSubObject({
41
36
  * @returns
42
37
  */
43
38
  function loadZohoAccessTokenSystemState(accessor) {
44
- return accessor.loadDocumentForId(ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE);
39
+ return accessor.loadDocumentForId(ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE);
45
40
  }
46
41
 
47
42
  /**
@@ -50,69 +45,71 @@ function loadZohoAccessTokenSystemState(accessor) {
50
45
  * @param collection
51
46
  */
52
47
  function firebaseZohoAccountsAccessTokenCacheService(systemStateCollection) {
53
- const systemStateDocumentAccessor = systemStateCollection.documentAccessor();
54
- const service = {
55
- loadZohoAccessTokenCache: function (serviceKey) {
56
- const cache = {
57
- loadCachedToken: async function () {
58
- const document = loadZohoAccessTokenSystemState(systemStateDocumentAccessor);
59
- const existingData = await document.snapshotData();
60
- let result = null;
61
- if (existingData != null) {
62
- const tokensArray = existingData?.data?.tokens ?? [];
63
- result = tokensArray.find(x => x.key === serviceKey);
64
- }
65
- return result;
66
- },
67
- updateCachedToken: async function (accessToken) {
68
- // run in a transaction
69
- await systemStateCollection.firestoreContext.runTransaction(async transaction => {
70
- const documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
71
- const existingData = await documentInTransaction.snapshotData();
72
- const existingTokens = existingData?.data?.tokens ?? [];
73
- const tokens = [
74
- // filter any potential old token for this service key
75
- ...existingTokens.filter(x => x.key !== serviceKey),
76
- // add the new token
77
- {
78
- ...accessToken,
79
- key: serviceKey
80
- }];
81
- const templateOrUpdate = {
82
- data: {
83
- tokens,
84
- lat: new Date()
85
- }
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
75
+ }
76
+ ];
77
+ const templateOrUpdate = {
78
+ data: {
79
+ tokens,
80
+ lat: new Date()
81
+ }
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
+ });
91
+ },
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()
100
+ }
101
+ };
102
+ // clear the tokens
103
+ if (existingData) {
104
+ await documentInTransaction.update(templateOrUpdate);
105
+ }
106
+ });
107
+ }
86
108
  };
87
- // create/update depending on the current document's existence
88
- if (!existingData) {
89
- await documentInTransaction.create(templateOrUpdate);
90
- } else {
91
- await documentInTransaction.update(templateOrUpdate);
92
- }
93
- });
94
- },
95
- clearCachedToken: async function () {
96
- await systemStateCollection.firestoreContext.runTransaction(async transaction => {
97
- const documentInTransaction = loadZohoAccessTokenSystemState(systemStateCollection.documentAccessorForTransaction(transaction));
98
- const existingData = await documentInTransaction.snapshotData();
99
- const templateOrUpdate = {
100
- data: {
101
- tokens: [],
102
- lat: new Date()
103
- }
104
- };
105
- // clear the tokens
106
- if (existingData) {
107
- await documentInTransaction.update(templateOrUpdate);
108
- }
109
- });
109
+ return cache;
110
110
  }
111
- };
112
- return cache;
113
- }
114
- };
115
- return service;
111
+ };
112
+ return service;
116
113
  }
117
114
 
118
115
  export { ZOHO_ACCESS_TOKEN_SYSTEM_STATE_TYPE, firebaseZohoAccountsAccessTokenCacheService, loadZohoAccessTokenSystemState, zohoAccessTokenSystemStateDataConverter, zohoAccessTokenSystemStateEmbeddedTokenConverter };
package/zoho/package.json CHANGED
@@ -1,29 +1,25 @@
1
1
  {
2
2
  "name": "@dereekb/firebase-server/zoho",
3
- "version": "13.0.0",
4
- "types": "./src/index.d.ts",
5
- "module": "./index.esm.js",
6
- "main": "./index.cjs.js",
3
+ "version": "13.0.2",
4
+ "peerDependencies": {
5
+ "@dereekb/date": "13.0.2",
6
+ "@dereekb/model": "13.0.2",
7
+ "@dereekb/nestjs": "13.0.2",
8
+ "@dereekb/rxjs": "13.0.2",
9
+ "@dereekb/firebase": "13.0.2",
10
+ "@dereekb/util": "13.0.2",
11
+ "@dereekb/zoho": "13.0.2"
12
+ },
7
13
  "exports": {
14
+ "./package.json": "./package.json",
8
15
  ".": {
9
- "types": "./src/index.d.ts",
10
- "node": {
11
- "require": "./index.cjs.js"
12
- },
13
- "browser": {
14
- "require": "./index.cjs.js",
15
- "import": "./index.esm.js"
16
- },
16
+ "module": "./index.esm.js",
17
+ "types": "./index.d.ts",
18
+ "import": "./index.cjs.mjs",
17
19
  "default": "./index.cjs.js"
18
20
  }
19
21
  },
20
- "peerDependencies": {
21
- "@dereekb/date": "13.0.0",
22
- "@dereekb/model": "13.0.0",
23
- "@dereekb/nestjs": "13.0.0",
24
- "@dereekb/rxjs": "13.0.0",
25
- "@dereekb/firebase": "13.0.0",
26
- "@dereekb/util": "13.0.0",
27
- "@dereekb/zoho": "13.0.0"
28
- }
22
+ "module": "./index.esm.js",
23
+ "main": "./index.cjs.js",
24
+ "types": "./index.d.ts"
29
25
  }