@live-change/google-authentication-service 0.8.40 → 0.8.42

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 (2) hide show
  1. package/offlineAccess.js +37 -3
  2. package/package.json +4 -4
package/offlineAccess.js CHANGED
@@ -38,13 +38,14 @@ export const OfflineAccess = definition.model({
38
38
  },
39
39
  indexes: {
40
40
  byUserAndScope: {
41
- property: ['user', 'scope']
41
+ multi: true,
42
+ property: ['user', 'scopes']
42
43
  }
43
44
  }
44
45
  })
45
46
 
46
47
  definition.view({
47
- name: 'myOfflineAccessByScope',
48
+ name: 'myUserOfflineAccessByScope',
48
49
  properties: {
49
50
  scope: {
50
51
  type: String
@@ -61,6 +62,25 @@ definition.view({
61
62
  }
62
63
  })
63
64
 
65
+ definition.view({
66
+ name: 'userOfflineAccessByScope',
67
+ properties: {
68
+ user: {
69
+ type: String
70
+ },
71
+ scope: {
72
+ type: String
73
+ }
74
+ },
75
+ returns: {
76
+ type: OfflineAccess
77
+ },
78
+ internal: true,
79
+ async daoPath({ user, scope }, { client }) {
80
+ return OfflineAccess.indexObjectPath('byUserAndScope', [user, scope])
81
+ }
82
+ })
83
+
64
84
  definition.event({
65
85
  name: "offlineAccessSaved",
66
86
  async execute({ user, refreshToken, timestamp }) {
@@ -119,13 +139,27 @@ definition.action({
119
139
  console.log("TOKENS", tokens)
120
140
  const scopes = tokens.scope.split(' ')
121
141
  if(tokens.token_type !== 'Bearer') throw new Error("Invalid token type "+tokens.token_type)
142
+ await OfflineAccess.update(user, {
143
+ id: user,
144
+ user,
145
+ scopes,
146
+ refreshToken: tokens.refresh_token,
147
+ accessToken: tokens.access_token,
148
+ accessTokenExpire: tokens.expires_in ? new Date(Date.now() + tokens.expires_in * 1000) : null,
149
+ lastRefresh: new Date()
150
+ })
122
151
  await service.triggerService({ type: 'googleAuthentication_setUserOwnedOfflineAccess', service: definition.name }, {
123
152
  user, scopes,
124
153
  accessToken: tokens.access_token,
125
154
  accessTokenExpire: tokens.expires_in ? new Date(Date.now() + tokens.expires_in * 1000) : null,
126
155
  refreshToken: tokens.refresh_token,
127
156
  })
128
-
157
+ await service.trigger({ type: 'googleOfflineAccessGained' }, {
158
+ user, scopes,
159
+ accessToken: tokens.access_token,
160
+ accessTokenExpire: tokens.expires_in ? new Date(Date.now() + tokens.expires_in * 1000) : null,
161
+ refreshToken: tokens.refresh_token,
162
+ })
129
163
  return {
130
164
  action: 'addOfflineAccessToken'
131
165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/google-authentication-service",
3
- "version": "0.8.40",
3
+ "version": "0.8.42",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,10 +21,10 @@
21
21
  "url": "https://www.viamage.com/"
22
22
  },
23
23
  "dependencies": {
24
- "@live-change/framework": "^0.8.40",
25
- "@live-change/relations-plugin": "^0.8.40",
24
+ "@live-change/framework": "^0.8.42",
25
+ "@live-change/relations-plugin": "^0.8.42",
26
26
  "google-auth-library": "9.0.0"
27
27
  },
28
- "gitHead": "5a12ec795f6fa16f30203aef3ad1534660fa5146",
28
+ "gitHead": "3aee0e7026e57fb72343e1254f0137959d958b6f",
29
29
  "type": "module"
30
30
  }