@leaddreamer/inventorylogic 0.0.3-beta.94 → 0.0.3-beta.95
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/README.md +334 -1
- package/business/AuthMachine/index.js +229 -0
- package/business/Services/index.js +212 -0
- package/business/User/index.js +1 -1
- package/business/boilerplate/index.js +2 -0
- package/business/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,9 @@ frontEnd and NodeJS BackEnd</p>
|
|
|
22
22
|
<dt><a href="#module_Addresses">Addresses</a></dt>
|
|
23
23
|
<dd><p>Types and functins for handling addresses</p>
|
|
24
24
|
</dd>
|
|
25
|
+
<dt><a href="#module_AuthMachine">AuthMachine</a></dt>
|
|
26
|
+
<dd><p>Typedefs and functions for an oAuth authentication generator</p>
|
|
27
|
+
</dd>
|
|
25
28
|
<dt><a href="#module_BusinessData">BusinessData</a></dt>
|
|
26
29
|
<dd><p>Functions for managing (potentially)private data for an organization.
|
|
27
30
|
Unified structure as a sub-record of organization, or CityManager accounts</p>
|
|
@@ -66,6 +69,10 @@ Unified structure as a sub-record of fan, organization, or CityManager accounts<
|
|
|
66
69
|
<dt><a href="#module_SquarespaceProduct">SquarespaceProduct</a></dt>
|
|
67
70
|
<dd><p>Typedefs, constants, support functions and database operations related to Products</p>
|
|
68
71
|
</dd>
|
|
72
|
+
<dt><a href="#module_Services">Services</a></dt>
|
|
73
|
+
<dd><p>Typedefs, constants, support functions and database operations related to supported Services Matrials
|
|
74
|
+
users</p>
|
|
75
|
+
</dd>
|
|
69
76
|
<dt><a href="#module_User">User</a></dt>
|
|
70
77
|
<dd><p>Typedefs, constants, support functions and database operations related to individual
|
|
71
78
|
users</p>
|
|
@@ -352,6 +359,143 @@ Fetches all address records for an account
|
|
|
352
359
|
|
|
353
360
|
### Addresses~ChainType : <code>WriteBatch</code> \| <code>Transaction</code> \| <code>void</code>
|
|
354
361
|
**Kind**: inner typedef of [<code>Addresses</code>](#module_Addresses)
|
|
362
|
+
<a name="module_AuthMachine"></a>
|
|
363
|
+
|
|
364
|
+
## AuthMachine
|
|
365
|
+
Typedefs and functions for an oAuth authentication generator
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
* [AuthMachine](#module_AuthMachine)
|
|
369
|
+
* [~GenerateAuthUrlOpts](#module_AuthMachine..GenerateAuthUrlOpts) : <code>object</code>
|
|
370
|
+
* [~TokenInfo](#module_AuthMachine..TokenInfo) : <code>object</code>
|
|
371
|
+
* [~OAuth2ClientEndpoints](#module_AuthMachine..OAuth2ClientEndpoints) : <code>object</code>
|
|
372
|
+
* [~OAuth2ClientOptions](#module_AuthMachine..OAuth2ClientOptions) : <code>object</code>
|
|
373
|
+
* [~initOAuthManager](#module_AuthMachine..initOAuthManager) ⇒ <code>OAuth2Client</code>
|
|
374
|
+
|
|
375
|
+
<a name="module_AuthMachine..GenerateAuthUrlOpts"></a>
|
|
376
|
+
|
|
377
|
+
### AuthMachine~GenerateAuthUrlOpts : <code>object</code>
|
|
378
|
+
Options object for GenerateAuthUrl
|
|
379
|
+
|
|
380
|
+
**Kind**: inner typedef of [<code>AuthMachine</code>](#module_AuthMachine)
|
|
381
|
+
**Properties**
|
|
382
|
+
|
|
383
|
+
| Name | Type | Description |
|
|
384
|
+
| --- | --- | --- |
|
|
385
|
+
| access_type | <code>"online"</code> \| <code>"offline"</code> | Recommended. Indicates whether your application can refresh access tokens when the user is not present at the browser. Valid parameter values are 'online', which is the default value, and 'offline'. Set the value to 'offline' if your application needs to refresh access tokens when the user is not present at the browser. This value instructs the Google authorization server to return a refresh token and an access token the first time that your application exchanges an authorization code for tokens. |
|
|
386
|
+
| hd | <code>string</code> | The hd (hosted domain) parameter streamlines the login process for G Suite hosted accounts. By including the domain of the G Suite user (for example, mycollege.edu), you can indicate that the account selection UI should be optimized for accounts at that domain. To optimize for G Suite accounts generally instead of just one domain, use an asterisk: hd=*. Don't rely on this UI optimization to control who can access your app, as client-side requests can be modified. Be sure to validate that the returned ID token has an hd claim value that matches what you expect (e.g. mycolledge.edu). Unlike the request parameter, the ID token claim is contained within a security token from Google, so the value can be trusted. |
|
|
387
|
+
| response_type | <code>"CODE"</code> | The 'response_type' will always be set to 'CODE'. |
|
|
388
|
+
| client_id | <code>string</code> | The client ID for your application. The value passed into the constructor will be used if not provided. You can find this value in the API Console. |
|
|
389
|
+
| redirect_url | <code>URL</code> | Determines where the API server redirects the user after the user completes the authorization flow. The value must exactly match one of the 'redirect_uri' values listed for your project in the API Console. Note that the http or https scheme, case, and trailing slash ('/') must all match. The value passed into the constructor will be used if not provided. |
|
|
390
|
+
| scope | <code>Array.string</code> \| <code>string</code> | Required. A space-delimited list of scopes that identify the resources that your application could access on the user's behalf. These values inform the consent screen that Google displays to the user. Scopes enable your application to only request access to the resources that it needs while also enabling users to control the amount of access that they grant to your application. Thus, there is an inverse relationship between the number of scopes requested and the likelihood of obtaining user consent. The OAuth 2.0 API Scopes document provides a full list of scopes that you might use to access Google APIs. We recommend that your application request access to authorization scopes in context whenever possible. By requesting access to user data in context, via incremental authorization, you help users to more easily understand why your application needs the access it is requesting. |
|
|
391
|
+
| state | <code>string</code> | Recommended. Specifies any string value that your application uses to maintain state between your authorization request and the authorization server's response. The server returns the exact value that you send as a name=value pair in the hash (#) fragment of the 'redirect_uri' after the user consents to or denies your application's access request. You can use this parameter for several purposes, such as directing the user to the correct resource in your application, sending nonces, and mitigating cross-site request forgery. Since your redirect_uri can be guessed, using a state value can increase your assurance that an incoming connection is the result of an authentication request. If you generate a random string or encode the hash of a cookie or another value that captures the client's state, you can validate the response to additionally ensure that the request and response originated in the same browser, providing protection against attacks such as cross-site request forgery. See the OpenID Connect documentation for an example of how to create and confirm a state token. |
|
|
392
|
+
| include_granted_scopes | <code>boolean</code> | Optional. Enables applications to use incremental authorization to request access to additional scopes in context. If you set this parameter's value to true and the authorization request is granted, then the new access token will also cover any scopes to which the user previously granted the application access. See the incremental authorization section for examples. |
|
|
393
|
+
| login_hint | <code>tring</code> | Optional. If your application knows which user is trying to authenticate, it can use this parameter to provide a hint to the Google Authentication Server. The server uses the hint to simplify the login flow either by prefilling the email field in the sign-in form or by selecting the appropriate multi-login session. Set the parameter value to an email address or sub identifier, which is equivalent to the user's Google ID. |
|
|
394
|
+
| prompt | <code>"none"</code> \| <code>"consent"</code> \| <code>"select\_account"</code> | Optional. A space-delimited, case-sensitive list of prompts to present the user. If you don't specify this parameter, the user will be prompted only the first time your app requests access. Possible values are: 'none' - Donot display any authentication or consent screens. Must not be specified with other values. 'consent' - Prompt the user for consent. 'select_account' - Prompt the user to select an account. |
|
|
395
|
+
| code_challenge_method | <code>"plain"</code> \| <code>"S256"</code> | Recommended. Specifies what method was used to encode a 'code_verifier' that will be used during authorization code exchange. This parameter must be used with the 'code_challenge' parameter. The value of the 'code_challenge_method' defaults to "plain" if not present in the request that includes a 'code_challenge'. The only supported values for this parameter are "S256" or "plain". |
|
|
396
|
+
| code_challenge | <code>string</code> | Recommended. Specifies an encoded 'code_verifier' that will be used as a server-side challenge during authorization code exchange. This parameter must be used with the 'code_challenge' parameter described above. |
|
|
397
|
+
| keyValues | <code>Array.object</code> | A way for developers and/or the auth team to provide a set of key value pairs to be added as query parameters to the authorization url. |
|
|
398
|
+
| keyValues.key | <code>string</code> | |
|
|
399
|
+
| keyValues.value | <code>string</code> | |
|
|
400
|
+
|
|
401
|
+
<a name="module_AuthMachine..TokenInfo"></a>
|
|
402
|
+
|
|
403
|
+
### AuthMachine~TokenInfo : <code>object</code>
|
|
404
|
+
Description of TokenInfo returned by oAuth manager
|
|
405
|
+
|
|
406
|
+
**Kind**: inner typedef of [<code>AuthMachine</code>](#module_AuthMachine)
|
|
407
|
+
**Properties**
|
|
408
|
+
|
|
409
|
+
| Name | Type | Description |
|
|
410
|
+
| --- | --- | --- |
|
|
411
|
+
| aud | <code>string</code> | The application that is the intended user of the access token. |
|
|
412
|
+
| user_id | <code>string</code> | This value lets you correlate profile information from multiple Google APIs. It is only present in the response if you included the profile scope in your request in step 1. The field value is an immutable identifier for the logged-in user that can be used to create and manage user sessions in your application. The identifier is the same regardless of which client ID is used to retrieve it. This enables multiple applications in the same organization to correlate profile information. |
|
|
413
|
+
| scopes | <code>Array.string</code> | An array of scopes that the user granted access to. |
|
|
414
|
+
| expiry_date | <code>number</code> | The datetime when the token becomes invalid. |
|
|
415
|
+
| sub | <code>string</code> | An identifier for the user, unique among all Google accounts and never reused. A Google account can have multiple emails at different points in time, but the sub value is never changed. Use sub within your application as the unique-identifier key for the user. |
|
|
416
|
+
| azp | <code>string</code> | The client_id of the authorized presenter. This claim is only needed when the party requesting the ID token is not the same as the audience of the ID token. This may be the case at Google for hybrid apps where a web application and Android app have a different client_id but share the same project. |
|
|
417
|
+
| access_type | <code>string</code> | Indicates whether your application can refresh access tokens when the user is not present at the browser. Valid parameter values are 'online', which is the default value, and 'offline'. Set the value to 'offline' if your application needs to refresh access tokens when the user is not present at the browser. This value instructs the Google authorization server to return a refresh token and an access token the first time that your application exchanges an authorization code for tokens. |
|
|
418
|
+
| email | <code>string</code> | The user's email address. This value may not be unique to this user and is not suitable for use as a primary key. Provided only if your scope included the email scope value. |
|
|
419
|
+
| email_verified | <code>boolean</code> | True if the user's e-mail address has been verified; otherwise false. |
|
|
420
|
+
|
|
421
|
+
<a name="module_AuthMachine..OAuth2ClientEndpoints"></a>
|
|
422
|
+
|
|
423
|
+
### AuthMachine~OAuth2ClientEndpoints : <code>object</code>
|
|
424
|
+
An object containing the various https endpoints for oAuth API
|
|
425
|
+
|
|
426
|
+
**Kind**: inner typedef of [<code>AuthMachine</code>](#module_AuthMachine)
|
|
427
|
+
**Properties**
|
|
428
|
+
|
|
429
|
+
| Name | Type | Description |
|
|
430
|
+
| --- | --- | --- |
|
|
431
|
+
| tokenInfoUrl | <code>string</code> | The endpoint for viewing access token information |
|
|
432
|
+
| oauth2AuthBaseUrl | <code>string</code> \| <code>URL</code> | The base URL for auth endpoints. |
|
|
433
|
+
| oauth2TokenUrl | <code>string</code> \| <code>URL</code> | The base endpoint for token retrieval |
|
|
434
|
+
| oauth2RevokeUrl | <code>string</code> \| <code>URL</code> | The base endpoint to revoke tokens. |
|
|
435
|
+
| oauth2FederatedSignonPemCertsUrl | <code>string</code> \| <code>URL</code> | Sign on certificates in PEM format. |
|
|
436
|
+
| oauth2FederatedSignonJwkCertsUrl | <code>string</code> \| <code>URL</code> | Sign on certificates in JWK format. |
|
|
437
|
+
| oauth2IapPublicKeyUrl | <code>string</code> \| <code>URL</code> | IAP Public Key URL. This URL contains a JSON dictionary that maps the `kid` claims to the public key values. |
|
|
438
|
+
|
|
439
|
+
**Example**
|
|
440
|
+
```js
|
|
441
|
+
'https://oauth2.googleapis.com/tokeninfo'
|
|
442
|
+
```
|
|
443
|
+
**Example**
|
|
444
|
+
```js
|
|
445
|
+
'https://accounts.google.com/o/oauth2/v2/auth'
|
|
446
|
+
```
|
|
447
|
+
**Example**
|
|
448
|
+
```js
|
|
449
|
+
'https://oauth2.googleapis.com/token'
|
|
450
|
+
```
|
|
451
|
+
**Example**
|
|
452
|
+
```js
|
|
453
|
+
'https://oauth2.googleapis.com/revoke'
|
|
454
|
+
```
|
|
455
|
+
**Example**
|
|
456
|
+
```js
|
|
457
|
+
'https://www.googleapis.com/oauth2/v1/certs'
|
|
458
|
+
```
|
|
459
|
+
**Example**
|
|
460
|
+
```js
|
|
461
|
+
'https://www.googleapis.com/oauth2/v3/certs'
|
|
462
|
+
```
|
|
463
|
+
**Example**
|
|
464
|
+
```js
|
|
465
|
+
'https://www.gstatic.com/iap/verify/public_key'
|
|
466
|
+
```
|
|
467
|
+
<a name="module_AuthMachine..OAuth2ClientOptions"></a>
|
|
468
|
+
|
|
469
|
+
### AuthMachine~OAuth2ClientOptions : <code>object</code>
|
|
470
|
+
The secret of this manager is you can take advantage of the "endpoints"
|
|
471
|
+
optional property to create a manager for *non*Google applications
|
|
472
|
+
|
|
473
|
+
**Kind**: inner typedef of [<code>AuthMachine</code>](#module_AuthMachine)
|
|
474
|
+
**Extends**: <code>AuthClientOptions,OAuth2JSONOptions</code>
|
|
475
|
+
**Properties**
|
|
476
|
+
|
|
477
|
+
| Name | Type | Description |
|
|
478
|
+
| --- | --- | --- |
|
|
479
|
+
| clientId | <code>string</code> | The authentication client ID. |
|
|
480
|
+
| clientSecret | <code>string</code> | The authentication client secret. |
|
|
481
|
+
| redirectUri | <code>string</code> | The URI to redirect to after completing the auth request. |
|
|
482
|
+
| endpoints | <code>OAuth2ClientEndpoints</code> | Customizable endpoints. |
|
|
483
|
+
| issuers | <code>string</code> | The allowed OAuth2 token issuers. |
|
|
484
|
+
| clientAuthentication | <code>"basic"</code> \| <code>"post"</code> \| <code>"none"</code> | The client authentication type. Supported values are basic, post, and none. Defaults to post if not provided. https://datatracker.ietf.org/doc/html/rfc7591#section-2 |
|
|
485
|
+
|
|
486
|
+
<a name="module_AuthMachine..initOAuthManager"></a>
|
|
487
|
+
|
|
488
|
+
### AuthMachine~initOAuthManager ⇒ <code>OAuth2Client</code>
|
|
489
|
+
Creates and initializing an oAuth2 manager *IF* it hasn't already
|
|
490
|
+
been created
|
|
491
|
+
|
|
492
|
+
**Kind**: inner typedef of [<code>AuthMachine</code>](#module_AuthMachine)
|
|
493
|
+
|
|
494
|
+
| Param | Type |
|
|
495
|
+
| --- | --- |
|
|
496
|
+
| manager | <code>class</code> |
|
|
497
|
+
| manager_options | <code>OAuth2ClientOptions</code> |
|
|
498
|
+
|
|
355
499
|
<a name="module_BusinessData"></a>
|
|
356
500
|
|
|
357
501
|
## BusinessData
|
|
@@ -3642,6 +3786,195 @@ value for the index; if *not* found add the variant.
|
|
|
3642
3786
|
| variantAttributes | <code>Array.string</code> | |
|
|
3643
3787
|
| variants | <code>Array.PhysicalProductVariant</code> | |
|
|
3644
3788
|
|
|
3789
|
+
<a name="module_Services"></a>
|
|
3790
|
+
|
|
3791
|
+
## Services
|
|
3792
|
+
Typedefs, constants, support functions and database operations related to supported Services Matrials
|
|
3793
|
+
users
|
|
3794
|
+
|
|
3795
|
+
|
|
3796
|
+
* [Services](#module_Services)
|
|
3797
|
+
* _static_
|
|
3798
|
+
* [.createService](#module_Services.createService) ⇒ <code>Promise.Service</code>
|
|
3799
|
+
* [.deleteService(service)](#module_Services.deleteService) ⇒ <code>Promise.<void></code>
|
|
3800
|
+
* [.deleteServiceById(service)](#module_Services.deleteServiceById) ⇒ <code>Promise.<void></code>
|
|
3801
|
+
* [.updateServiceByID(service)](#module_Services.updateServiceByID) ⇒ <code>promise.Service</code>
|
|
3802
|
+
* [.updateService(service)](#module_Services.updateService) ⇒ <code>promise.Service</code>
|
|
3803
|
+
* [.knownService(Id)](#module_Services.knownService) ⇒ <code>Promise.boolean</code>
|
|
3804
|
+
* [.fetchServices()](#module_Services.fetchServices) ⇒ <code>Array.Service</code>
|
|
3805
|
+
* [.fetchServicesPaginated(limit)](#module_Services.fetchServicesPaginated) ⇒ <code>PaginatedFetch</code>
|
|
3806
|
+
* [.fetchService(serviceId)](#module_Services.fetchService) ⇒ <code>Promise.Service</code>
|
|
3807
|
+
* [.fetchServiceName(serviceId)](#module_Services.fetchServiceName) ⇒ <code>Promise.string</code>
|
|
3808
|
+
* _inner_
|
|
3809
|
+
* [~ServiceDefault](#module_Services..ServiceDefault) : <code>ServiceDescriptor</code>
|
|
3810
|
+
* [~ServiceDefaultForm](#module_Services..ServiceDefaultForm) : <code>ServiceDescriptor</code>
|
|
3811
|
+
* [~summarizeService(service)](#module_Services..summarizeService) ⇒ <code>string</code>
|
|
3812
|
+
* [~ServiceDescriptor](#module_Services..ServiceDescriptor) : <code>object</code>
|
|
3813
|
+
* [~PaginatedFetch](#module_Services..PaginatedFetch) : <code>object</code>
|
|
3814
|
+
|
|
3815
|
+
<a name="module_Services.createService"></a>
|
|
3816
|
+
|
|
3817
|
+
### Services.createService ⇒ <code>Promise.Service</code>
|
|
3818
|
+
**Kind**: static constant of [<code>Services</code>](#module_Services)
|
|
3819
|
+
|
|
3820
|
+
| Param | Type | Description |
|
|
3821
|
+
| --- | --- | --- |
|
|
3822
|
+
| service | <code>ServiceDescriptor</code> | minimal record of Service |
|
|
3823
|
+
|
|
3824
|
+
<a name="module_Services.deleteService"></a>
|
|
3825
|
+
|
|
3826
|
+
### Services.deleteService(service) ⇒ <code>Promise.<void></code>
|
|
3827
|
+
**Kind**: static method of [<code>Services</code>](#module_Services)
|
|
3828
|
+
|
|
3829
|
+
| Param | Type |
|
|
3830
|
+
| --- | --- |
|
|
3831
|
+
| service | <code>ServiceDescriptor</code> |
|
|
3832
|
+
|
|
3833
|
+
<a name="module_Services.deleteServiceById"></a>
|
|
3834
|
+
|
|
3835
|
+
### Services.deleteServiceById(service) ⇒ <code>Promise.<void></code>
|
|
3836
|
+
**Kind**: static method of [<code>Services</code>](#module_Services)
|
|
3837
|
+
|
|
3838
|
+
| Param | Type | Description |
|
|
3839
|
+
| --- | --- | --- |
|
|
3840
|
+
| service | <code>ServiceDescriptor</code> | minimal record of Service |
|
|
3841
|
+
| service.Id | <code>string</code> | record Id of account |
|
|
3842
|
+
|
|
3843
|
+
<a name="module_Services.updateServiceByID"></a>
|
|
3844
|
+
|
|
3845
|
+
### Services.updateServiceByID(service) ⇒ <code>promise.Service</code>
|
|
3846
|
+
writes record back to database. Assumes only Id is valid
|
|
3847
|
+
|
|
3848
|
+
**Kind**: static method of [<code>Services</code>](#module_Services)
|
|
3849
|
+
**Returns**: <code>promise.Service</code> - a copy of the data written
|
|
3850
|
+
|
|
3851
|
+
| Param | Type | Description |
|
|
3852
|
+
| --- | --- | --- |
|
|
3853
|
+
| service | <code>ServiceDescriptor</code> | a partially-populated service record for updates |
|
|
3854
|
+
|
|
3855
|
+
<a name="module_Services.updateService"></a>
|
|
3856
|
+
|
|
3857
|
+
### Services.updateService(service) ⇒ <code>promise.Service</code>
|
|
3858
|
+
writes record back to database. Assumes only Id is valid
|
|
3859
|
+
|
|
3860
|
+
**Kind**: static method of [<code>Services</code>](#module_Services)
|
|
3861
|
+
**Returns**: <code>promise.Service</code> - a copy of the data written
|
|
3862
|
+
|
|
3863
|
+
| Param | Type | Description |
|
|
3864
|
+
| --- | --- | --- |
|
|
3865
|
+
| service | <code>ServiceDescriptor</code> | a partially-populated service record for updates |
|
|
3866
|
+
|
|
3867
|
+
<a name="module_Services.knownService"></a>
|
|
3868
|
+
|
|
3869
|
+
### Services.knownService(Id) ⇒ <code>Promise.boolean</code>
|
|
3870
|
+
Checks if this is a known Service Id
|
|
3871
|
+
|
|
3872
|
+
**Kind**: static method of [<code>Services</code>](#module_Services)
|
|
3873
|
+
**Returns**: <code>Promise.boolean</code> - true is this Id is in database
|
|
3874
|
+
|
|
3875
|
+
| Param | Type | Description |
|
|
3876
|
+
| --- | --- | --- |
|
|
3877
|
+
| Id | <code>string</code> | Id value to check |
|
|
3878
|
+
|
|
3879
|
+
<a name="module_Services.fetchServices"></a>
|
|
3880
|
+
|
|
3881
|
+
### Services.fetchServices() ⇒ <code>Array.Service</code>
|
|
3882
|
+
Fetches ALL Service records. Not very useful
|
|
3883
|
+
|
|
3884
|
+
**Kind**: static method of [<code>Services</code>](#module_Services)
|
|
3885
|
+
<a name="module_Services.fetchServicesPaginated"></a>
|
|
3886
|
+
|
|
3887
|
+
### Services.fetchServicesPaginated(limit) ⇒ <code>PaginatedFetch</code>
|
|
3888
|
+
Fetchs an object to fetch pages of service data, ascending by name, "limit" at a time
|
|
3889
|
+
|
|
3890
|
+
**Kind**: static method of [<code>Services</code>](#module_Services)
|
|
3891
|
+
**Returns**: <code>PaginatedFetch</code> - object with pagination methods
|
|
3892
|
+
|
|
3893
|
+
| Param | Type |
|
|
3894
|
+
| --- | --- |
|
|
3895
|
+
| limit | <code>number</code> |
|
|
3896
|
+
|
|
3897
|
+
<a name="module_Services.fetchService"></a>
|
|
3898
|
+
|
|
3899
|
+
### Services.fetchService(serviceId) ⇒ <code>Promise.Service</code>
|
|
3900
|
+
Fetches a single Service record by Id
|
|
3901
|
+
|
|
3902
|
+
**Kind**: static method of [<code>Services</code>](#module_Services)
|
|
3903
|
+
|
|
3904
|
+
| Param | Type |
|
|
3905
|
+
| --- | --- |
|
|
3906
|
+
| serviceId | <code>ServiceDescriptor.id</code> |
|
|
3907
|
+
|
|
3908
|
+
<a name="module_Services.fetchServiceName"></a>
|
|
3909
|
+
|
|
3910
|
+
### Services.fetchServiceName(serviceId) ⇒ <code>Promise.string</code>
|
|
3911
|
+
Fetches and returns the summarized name from a Service record
|
|
3912
|
+
|
|
3913
|
+
**Kind**: static method of [<code>Services</code>](#module_Services)
|
|
3914
|
+
**Returns**: <code>Promise.string</code> - the summarized name from the record
|
|
3915
|
+
|
|
3916
|
+
| Param | Type |
|
|
3917
|
+
| --- | --- |
|
|
3918
|
+
| serviceId | <code>string</code> |
|
|
3919
|
+
|
|
3920
|
+
<a name="module_Services..ServiceDefault"></a>
|
|
3921
|
+
|
|
3922
|
+
### Services~ServiceDefault : <code>ServiceDescriptor</code>
|
|
3923
|
+
**Kind**: inner constant of [<code>Services</code>](#module_Services)
|
|
3924
|
+
**Default**: <code>{"Id":null,"refPath":null,"name":null,"api_base_url":null,"auth":"","endpoints":""}</code>
|
|
3925
|
+
**Read only**: true
|
|
3926
|
+
<a name="module_Services..ServiceDefaultForm"></a>
|
|
3927
|
+
|
|
3928
|
+
### Services~ServiceDefaultForm : <code>ServiceDescriptor</code>
|
|
3929
|
+
**Kind**: inner constant of [<code>Services</code>](#module_Services)
|
|
3930
|
+
**Default**: <code>{"description":"text","unit":"","rate":"number","MATERIAL":"","image":"url"}</code>
|
|
3931
|
+
**Read only**: true
|
|
3932
|
+
<a name="module_Services..summarizeService"></a>
|
|
3933
|
+
|
|
3934
|
+
### Services~summarizeService(service) ⇒ <code>string</code>
|
|
3935
|
+
Returns a standardized formatted name string
|
|
3936
|
+
|
|
3937
|
+
**Kind**: inner method of [<code>Services</code>](#module_Services)
|
|
3938
|
+
**Returns**: <code>string</code> - formatted name string
|
|
3939
|
+
|
|
3940
|
+
| Param | Type |
|
|
3941
|
+
| --- | --- |
|
|
3942
|
+
| service | <code>ServiceDescriptor</code> |
|
|
3943
|
+
|
|
3944
|
+
<a name="module_Services..ServiceDescriptor"></a>
|
|
3945
|
+
|
|
3946
|
+
### Services~ServiceDescriptor : <code>object</code>
|
|
3947
|
+
a record
|
|
3948
|
+
|
|
3949
|
+
**Kind**: inner typedef of [<code>Services</code>](#module_Services)
|
|
3950
|
+
**Properties**
|
|
3951
|
+
|
|
3952
|
+
| Name | Type | Description |
|
|
3953
|
+
| --- | --- | --- |
|
|
3954
|
+
| Id | <code>string</code> | Id of document (redundant for convenience) |
|
|
3955
|
+
| refPath | <code>string</code> | if from database, full path to document |
|
|
3956
|
+
| name | <code>string</code> | descriptive name for an available service |
|
|
3957
|
+
| api_base_url | <code>string</code> | base url of API endpoints |
|
|
3958
|
+
| auth | <code>OAuth2ClientOptions</code> | |
|
|
3959
|
+
| endpoints | <code>OAuth2ClientEndpoints</code> | |
|
|
3960
|
+
|
|
3961
|
+
<a name="module_Services..PaginatedFetch"></a>
|
|
3962
|
+
|
|
3963
|
+
### Services~PaginatedFetch : <code>object</code>
|
|
3964
|
+
An object to allow for paginating a table read from Firestore. REQUIRES a sorting choice
|
|
3965
|
+
|
|
3966
|
+
**Kind**: inner typedef of [<code>Services</code>](#module_Services)
|
|
3967
|
+
**Properties**
|
|
3968
|
+
|
|
3969
|
+
| Name | Type | Description |
|
|
3970
|
+
| --- | --- | --- |
|
|
3971
|
+
| Query | <code>Query</code> | that forms basis for the table read |
|
|
3972
|
+
| limit | <code>number</code> | page size |
|
|
3973
|
+
| snapshot | <code>QuerySnapshot</code> | last successful snapshot/page fetched |
|
|
3974
|
+
| status | <code>enum</code> | status of pagination object |
|
|
3975
|
+
| PageForward | <code>method</code> | pages the fetch forward |
|
|
3976
|
+
| PageBack | <code>method</code> | pages the fetch backward |
|
|
3977
|
+
|
|
3645
3978
|
<a name="module_User"></a>
|
|
3646
3979
|
|
|
3647
3980
|
## User
|
|
@@ -3715,7 +4048,7 @@ Builds a User record from the authentication "user" data
|
|
|
3715
4048
|
|
|
3716
4049
|
| Param | Type |
|
|
3717
4050
|
| --- | --- |
|
|
3718
|
-
| user | <code>
|
|
4051
|
+
| user | <code>UserObject</code> |
|
|
3719
4052
|
| user.isAnonymous | <code>boolean</code> |
|
|
3720
4053
|
| user.displayName | <code>string</code> |
|
|
3721
4054
|
| user.photoURL | <code>string</code> |
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typedefs and functions for an oAuth authentication generator
|
|
3
|
+
* @module AuthMachine
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options object for GenerateAuthUrl
|
|
8
|
+
* @typedef {object} GenerateAuthUrlOpts
|
|
9
|
+
* @property {?"online"|"offline"} access_type
|
|
10
|
+
* Recommended. Indicates whether your application can refresh access tokens
|
|
11
|
+
* when the user is not present at the browser. Valid parameter values are
|
|
12
|
+
* 'online', which is the default value, and 'offline'. Set the value to
|
|
13
|
+
* 'offline' if your application needs to refresh access tokens when the user
|
|
14
|
+
* is not present at the browser. This value instructs the Google
|
|
15
|
+
* authorization server to return a refresh token and an access token the
|
|
16
|
+
* first time that your application exchanges an authorization code for
|
|
17
|
+
* tokens.
|
|
18
|
+
* @property {?string} hd
|
|
19
|
+
* The hd (hosted domain) parameter streamlines the login process for G Suite
|
|
20
|
+
* hosted accounts. By including the domain of the G Suite user (for example,
|
|
21
|
+
* mycollege.edu), you can indicate that the account selection UI should be
|
|
22
|
+
* optimized for accounts at that domain. To optimize for G Suite accounts
|
|
23
|
+
* generally instead of just one domain, use an asterisk: hd=*.
|
|
24
|
+
* Don't rely on this UI optimization to control who can access your app,
|
|
25
|
+
* as client-side requests can be modified. Be sure to validate that the
|
|
26
|
+
* returned ID token has an hd claim value that matches what you expect
|
|
27
|
+
* (e.g. mycolledge.edu). Unlike the request parameter, the ID token claim is
|
|
28
|
+
* contained within a security token from Google, so the value can be trusted.
|
|
29
|
+
* @property {?"CODE"} response_type
|
|
30
|
+
* The 'response_type' will always be set to 'CODE'.
|
|
31
|
+
* @property {?string} client_id
|
|
32
|
+
* The client ID for your application. The value passed into the constructor
|
|
33
|
+
* will be used if not provided. You can find this value in the API Console.
|
|
34
|
+
* @property {?URL} redirect_url
|
|
35
|
+
* Determines where the API server redirects the user after the user
|
|
36
|
+
* completes the authorization flow. The value must exactly match one of the
|
|
37
|
+
* 'redirect_uri' values listed for your project in the API Console. Note that
|
|
38
|
+
* the http or https scheme, case, and trailing slash ('/') must all match.
|
|
39
|
+
* The value passed into the constructor will be used if not provided.
|
|
40
|
+
* @property {Array.string|string} scope
|
|
41
|
+
* Required. A space-delimited list of scopes that identify the resources that
|
|
42
|
+
* your application could access on the user's behalf. These values inform the
|
|
43
|
+
* consent screen that Google displays to the user. Scopes enable your
|
|
44
|
+
* application to only request access to the resources that it needs while
|
|
45
|
+
* also enabling users to control the amount of access that they grant to your
|
|
46
|
+
* application. Thus, there is an inverse relationship between the number of
|
|
47
|
+
* scopes requested and the likelihood of obtaining user consent. The
|
|
48
|
+
* OAuth 2.0 API Scopes document provides a full list of scopes that you might
|
|
49
|
+
* use to access Google APIs. We recommend that your application request
|
|
50
|
+
* access to authorization scopes in context whenever possible. By requesting
|
|
51
|
+
* access to user data in context, via incremental authorization, you help
|
|
52
|
+
* users to more easily understand why your application needs the access it is
|
|
53
|
+
* requesting.
|
|
54
|
+
* @property {?string} state
|
|
55
|
+
* Recommended. Specifies any string value that your application uses to
|
|
56
|
+
* maintain state between your authorization request and the authorization
|
|
57
|
+
* server's response. The server returns the exact value that you send as a
|
|
58
|
+
* name=value pair in the hash (#) fragment of the 'redirect_uri' after the
|
|
59
|
+
* user consents to or denies your application's access request. You can use
|
|
60
|
+
* this parameter for several purposes, such as directing the user to the
|
|
61
|
+
* correct resource in your application, sending nonces, and mitigating
|
|
62
|
+
* cross-site request forgery. Since your redirect_uri can be guessed, using a
|
|
63
|
+
* state value can increase your assurance that an incoming connection is the
|
|
64
|
+
* result of an authentication request. If you generate a random string or
|
|
65
|
+
* encode the hash of a cookie or another value that captures the client's
|
|
66
|
+
* state, you can validate the response to additionally ensure that the
|
|
67
|
+
* request and response originated in the same browser, providing protection
|
|
68
|
+
* against attacks such as cross-site request forgery. See the OpenID Connect
|
|
69
|
+
* documentation for an example of how to create and confirm a state token.
|
|
70
|
+
* @property {?boolean} include_granted_scopes
|
|
71
|
+
* Optional. Enables applications to use incremental authorization to request
|
|
72
|
+
* access to additional scopes in context. If you set this parameter's value
|
|
73
|
+
* to true and the authorization request is granted, then the new access token
|
|
74
|
+
* will also cover any scopes to which the user previously granted the
|
|
75
|
+
* application access. See the incremental authorization section for examples.
|
|
76
|
+
* @property {?tring} login_hint
|
|
77
|
+
* Optional. If your application knows which user is trying to authenticate,
|
|
78
|
+
* it can use this parameter to provide a hint to the Google Authentication
|
|
79
|
+
* Server. The server uses the hint to simplify the login flow either by
|
|
80
|
+
* prefilling the email field in the sign-in form or by selecting the
|
|
81
|
+
* appropriate multi-login session. Set the parameter value to an email
|
|
82
|
+
* address or sub identifier, which is equivalent to the user's Google ID.
|
|
83
|
+
* @property {?"none"|"consent"|"select_account"} prompt
|
|
84
|
+
* Optional. A space-delimited, case-sensitive list of prompts to present the
|
|
85
|
+
* user. If you don't specify this parameter, the user will be prompted only
|
|
86
|
+
* the first time your app requests access. Possible values are:
|
|
87
|
+
*
|
|
88
|
+
* 'none' - Donot display any authentication or consent screens. Must not be
|
|
89
|
+
* specified with other values.
|
|
90
|
+
* 'consent' - Prompt the user for consent.
|
|
91
|
+
* 'select_account' - Prompt the user to select an account.
|
|
92
|
+
* @property {?"plain"|"S256"} code_challenge_method
|
|
93
|
+
* Recommended. Specifies what method was used to encode a 'code_verifier'
|
|
94
|
+
* that will be used during authorization code exchange. This parameter must
|
|
95
|
+
* be used with the 'code_challenge' parameter. The value of the
|
|
96
|
+
* 'code_challenge_method' defaults to "plain" if not present in the request
|
|
97
|
+
* that includes a 'code_challenge'. The only supported values for this
|
|
98
|
+
* parameter are "S256" or "plain".
|
|
99
|
+
* @property {?string} code_challenge
|
|
100
|
+
* Recommended. Specifies an encoded 'code_verifier' that will be used as a
|
|
101
|
+
* server-side challenge during authorization code exchange. This parameter
|
|
102
|
+
* must be used with the 'code_challenge' parameter described above.
|
|
103
|
+
* @property {Array.object} keyValues
|
|
104
|
+
* A way for developers and/or the auth team to provide a set of key value
|
|
105
|
+
* pairs to be added as query parameters to the authorization url.
|
|
106
|
+
* @property {string} keyValues.key
|
|
107
|
+
* @property {string} keyValues.value
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Description of TokenInfo returned by oAuth manager
|
|
112
|
+
* @typedef {object} TokenInfo
|
|
113
|
+
* @property {string} aud
|
|
114
|
+
* The application that is the intended user of the access token.
|
|
115
|
+
* @property {?string} user_id
|
|
116
|
+
* This value lets you correlate profile information from multiple Google
|
|
117
|
+
* APIs. It is only present in the response if you included the profile scope
|
|
118
|
+
* in your request in step 1. The field value is an immutable identifier for
|
|
119
|
+
* the logged-in user that can be used to create and manage user sessions in
|
|
120
|
+
* your application. The identifier is the same regardless of which client ID
|
|
121
|
+
* is used to retrieve it. This enables multiple applications in the same
|
|
122
|
+
* organization to correlate profile information.
|
|
123
|
+
* @property {Array.string} scopes
|
|
124
|
+
* An array of scopes that the user granted access to.
|
|
125
|
+
* @property {number} expiry_date
|
|
126
|
+
* The datetime when the token becomes invalid.
|
|
127
|
+
* @property {?string} sub
|
|
128
|
+
* An identifier for the user, unique among all Google accounts and never
|
|
129
|
+
* reused. A Google account can have multiple emails at different points in
|
|
130
|
+
* time, but the sub value is never changed. Use sub within your application
|
|
131
|
+
* as the unique-identifier key for the user.
|
|
132
|
+
* @property {?string} azp
|
|
133
|
+
* The client_id of the authorized presenter. This claim is only needed when
|
|
134
|
+
* the party requesting the ID token is not the same as the audience of the ID
|
|
135
|
+
* token. This may be the case at Google for hybrid apps where a web
|
|
136
|
+
* application and Android app have a different client_id but share the same
|
|
137
|
+
* project.
|
|
138
|
+
* @property {?string} access_type
|
|
139
|
+
* Indicates whether your application can refresh access tokens
|
|
140
|
+
* when the user is not present at the browser. Valid parameter values are
|
|
141
|
+
* 'online', which is the default value, and 'offline'. Set the value to
|
|
142
|
+
* 'offline' if your application needs to refresh access tokens when the user
|
|
143
|
+
* is not present at the browser. This value instructs the Google
|
|
144
|
+
* authorization server to return a refresh token and an access token the
|
|
145
|
+
* first time that your application exchanges an authorization code for
|
|
146
|
+
* tokens.
|
|
147
|
+
* @property {?string} email
|
|
148
|
+
* The user's email address. This value may not be unique to this user and
|
|
149
|
+
* is not suitable for use as a primary key. Provided only if your scope
|
|
150
|
+
* included the email scope value.
|
|
151
|
+
* @property {?boolean} email_verified
|
|
152
|
+
* True if the user's e-mail address has been verified; otherwise false.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* An object containing the various https endpoints for oAuth API
|
|
157
|
+
* @typedef {object} OAuth2ClientEndpoints
|
|
158
|
+
* @property {string} tokenInfoUrl
|
|
159
|
+
* The endpoint for viewing access token information
|
|
160
|
+
* @example
|
|
161
|
+
* 'https://oauth2.googleapis.com/tokeninfo'
|
|
162
|
+
* @property {string|URL} oauth2AuthBaseUrl
|
|
163
|
+
* The base URL for auth endpoints.
|
|
164
|
+
* @example
|
|
165
|
+
* 'https://accounts.google.com/o/oauth2/v2/auth'
|
|
166
|
+
* @property {string|URL} oauth2TokenUrl
|
|
167
|
+
* The base endpoint for token retrieval
|
|
168
|
+
* @example
|
|
169
|
+
* 'https://oauth2.googleapis.com/token'
|
|
170
|
+
* @property {string|URL} oauth2RevokeUrl
|
|
171
|
+
* The base endpoint to revoke tokens.
|
|
172
|
+
* @example
|
|
173
|
+
* 'https://oauth2.googleapis.com/revoke'
|
|
174
|
+
* @property {string|URL} oauth2FederatedSignonPemCertsUrl
|
|
175
|
+
* Sign on certificates in PEM format.
|
|
176
|
+
* @example
|
|
177
|
+
* 'https://www.googleapis.com/oauth2/v1/certs'
|
|
178
|
+
* @property {string|URL} oauth2FederatedSignonJwkCertsUrl
|
|
179
|
+
* Sign on certificates in JWK format.
|
|
180
|
+
* @example
|
|
181
|
+
* 'https://www.googleapis.com/oauth2/v3/certs'
|
|
182
|
+
* @property {string|URL} oauth2IapPublicKeyUrl
|
|
183
|
+
* IAP Public Key URL.
|
|
184
|
+
* This URL contains a JSON dictionary that maps the `kid` claims to the public key values.
|
|
185
|
+
* @example
|
|
186
|
+
* 'https://www.gstatic.com/iap/verify/public_key'
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The secret of this manager is you can take advantage of the "endpoints"
|
|
191
|
+
* optional property to create a manager for *non*Google applications
|
|
192
|
+
* @typedef {object} OAuth2ClientOptions
|
|
193
|
+
* @extends AuthClientOptions,OAuth2JSONOptions
|
|
194
|
+
* @alias {@link OAuth2JSONOptions.client_id}
|
|
195
|
+
* @property {?string} clientId
|
|
196
|
+
* The authentication client ID.
|
|
197
|
+
* @alias {@link OAuth2JSONOptions.client_secret}
|
|
198
|
+
* @property {?string} clientSecret
|
|
199
|
+
* The authentication client secret.
|
|
200
|
+
* @alias {@link OAuth2JSONOptions.redirect_uris}
|
|
201
|
+
* @property {?string} redirectUri
|
|
202
|
+
* The URI to redirect to after completing the auth request.
|
|
203
|
+
* @property {?OAuth2ClientEndpoints} endpoints
|
|
204
|
+
* Customizable endpoints.
|
|
205
|
+
* @property {?string} issuers
|
|
206
|
+
* The allowed OAuth2 token issuers.
|
|
207
|
+
* @property {?"basic"|"post"|"none"} clientAuthentication
|
|
208
|
+
* The client authentication type. Supported values are basic, post, and none.
|
|
209
|
+
* Defaults to post if not provided.
|
|
210
|
+
* https://datatracker.ietf.org/doc/html/rfc7591#section-2
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Creates and initializing an oAuth2 manager *IF* it hasn't already
|
|
215
|
+
* been created
|
|
216
|
+
* @callback initOAuthManager
|
|
217
|
+
* @param {class} manager
|
|
218
|
+
* @param {OAuth2ClientOptions} manager_options
|
|
219
|
+
* @returns {OAuth2Client}
|
|
220
|
+
*/
|
|
221
|
+
export function initOAuthManager(manager, manager_options) {
|
|
222
|
+
if (manager)
|
|
223
|
+
return manager;
|
|
224
|
+
else {
|
|
225
|
+
return new OAuth2Client(
|
|
226
|
+
manager_options
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typedefs, constants, support functions and database operations related to supported Services Matrials
|
|
3
|
+
* users
|
|
4
|
+
* @module Services
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
writeRecord,
|
|
9
|
+
writeBack,
|
|
10
|
+
updateRecord,
|
|
11
|
+
fetchRecord,
|
|
12
|
+
collectRecords,
|
|
13
|
+
deleteRecord,
|
|
14
|
+
PaginateFetch,
|
|
15
|
+
} from "@leaddreamer/firebase-wrapper";
|
|
16
|
+
import { Forms, fillForm } from "@leaddreamer/staticforms";
|
|
17
|
+
|
|
18
|
+
import { SERVICES } from "../boilerplate/index.js";
|
|
19
|
+
|
|
20
|
+
//////////////////////////////////////////////////////////////////////
|
|
21
|
+
// Constants
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* a record
|
|
25
|
+
* @typedef {object} ServiceDescriptor
|
|
26
|
+
* @property {string} Id Id of document (redundant for convenience)
|
|
27
|
+
* @property {string} refPath if from database, full path to document
|
|
28
|
+
* @property {string} name descriptive name for an available service
|
|
29
|
+
* @property {string} api_base_url base url of API endpoints
|
|
30
|
+
* @property {OAuth2ClientOptions} auth
|
|
31
|
+
* @property {OAuth2ClientEndpoints} endpoints
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @readonly
|
|
36
|
+
* @constant
|
|
37
|
+
* @type {ServiceDescriptor}
|
|
38
|
+
* @default
|
|
39
|
+
*/
|
|
40
|
+
const ServiceDefault = {
|
|
41
|
+
Id: null,
|
|
42
|
+
refPath: null,
|
|
43
|
+
name: null,
|
|
44
|
+
api_base_url: null,
|
|
45
|
+
auth: {},
|
|
46
|
+
endpoints: {},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @readonly
|
|
51
|
+
* @constant
|
|
52
|
+
* @type {ServiceDescriptor}
|
|
53
|
+
* @default
|
|
54
|
+
*/
|
|
55
|
+
const ServiceDefaultForm = {
|
|
56
|
+
description: "text",
|
|
57
|
+
unit: `lookup:${UNITS}`,
|
|
58
|
+
rate: "number",
|
|
59
|
+
[MATERIAL]:`lookup:${MATERIAL}`,
|
|
60
|
+
image: "url",
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
Forms.Base[SERVICES] = ServiceDefault;
|
|
64
|
+
Forms.BaseForm[SERVICES] = ServiceDefaultForm;
|
|
65
|
+
Forms.CreateForm[SERVICES] = ServiceDefaultForm;
|
|
66
|
+
Forms.Summarize[SERVICES] = summarizeService;
|
|
67
|
+
Forms.Save[SERVICES] = updateService;
|
|
68
|
+
Forms.SearchBy[SERVICES] = "description";
|
|
69
|
+
|
|
70
|
+
//////////////////////////////////////////////////////////////////////
|
|
71
|
+
// record operations
|
|
72
|
+
/**
|
|
73
|
+
* @param {ServiceDescriptor} service
|
|
74
|
+
* @returns {Promise<void>}
|
|
75
|
+
*/
|
|
76
|
+
export async function deleteService(service) {
|
|
77
|
+
return deleteRecord(service, SERVICES);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @param {ServiceDescriptor} service minimal record of Service
|
|
82
|
+
* @param {!string} service.Id record Id of account
|
|
83
|
+
* @returns {Promise<void>}
|
|
84
|
+
*/
|
|
85
|
+
export async function deleteServiceById(service) {
|
|
86
|
+
if (!service?.Id) return;
|
|
87
|
+
|
|
88
|
+
return deleteRecord(service, SERVICES);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @param {ServiceDescriptor} service minimal record of Service
|
|
93
|
+
* @returns {Promise.Service}
|
|
94
|
+
*/
|
|
95
|
+
export const createService = (service) => {
|
|
96
|
+
//need a "no duplicate" function - whatever that means in this context
|
|
97
|
+
return writeRecord(SERVICES, service);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* writes record back to database. Assumes only Id is valid
|
|
102
|
+
* @param {ServiceDescriptor} service a partially-populated service record for updates
|
|
103
|
+
* @returns {promise.Service} a copy of the data written
|
|
104
|
+
*/
|
|
105
|
+
export async function updateServiceByID(service, parent = null) {
|
|
106
|
+
// will update just the fields provided
|
|
107
|
+
return writeBack({
|
|
108
|
+
...service,
|
|
109
|
+
refPath: `${parent?.refPath}/${SERVICES}/${service.Id}`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* writes record back to database. Assumes only Id is valid
|
|
115
|
+
* @param {ServiceDescriptor} service a partially-populated service record for updates
|
|
116
|
+
* @returns {promise.Service} a copy of the data written
|
|
117
|
+
*/
|
|
118
|
+
export async function updateService(service) {
|
|
119
|
+
|
|
120
|
+
return updateRecord(
|
|
121
|
+
fillForm(service, SERVICES), //saves only APPROPRIATE fields -does NOT populate missing fields
|
|
122
|
+
null,
|
|
123
|
+
SERVICE
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//////////////////////////////////////////////////////////////////////
|
|
128
|
+
// fetches
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Checks if this is a known Service Id
|
|
132
|
+
* @param {!string} Id Id value to check
|
|
133
|
+
* @returns {Promise.boolean} true is this Id is in database
|
|
134
|
+
*/
|
|
135
|
+
export async function knownService(Id) {
|
|
136
|
+
let exists = true;
|
|
137
|
+
try {
|
|
138
|
+
await fetchService(Id);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
exists = false;
|
|
141
|
+
}
|
|
142
|
+
return exists;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
//////////////////////////////////////////////////////////////////////
|
|
146
|
+
// fetches
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Fetches ALL Service records. Not very useful
|
|
150
|
+
* @returns {Array.Service}
|
|
151
|
+
*/
|
|
152
|
+
export async function fetchServices() {
|
|
153
|
+
return collectRecords(SERVICES);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* An object to allow for paginating a table read from Firestore. REQUIRES a sorting choice
|
|
158
|
+
* @typedef {object} PaginatedFetch
|
|
159
|
+
* @property {Query} Query that forms basis for the table read
|
|
160
|
+
* @property {number} limit page size
|
|
161
|
+
* @property {QuerySnapshot} snapshot last successful snapshot/page fetched
|
|
162
|
+
* @property {enum} status status of pagination object
|
|
163
|
+
* @property {method} PageForward pages the fetch forward
|
|
164
|
+
* @property {method} PageBack pages the fetch backward
|
|
165
|
+
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Fetchs an object to fetch pages of service data, ascending by name, "limit" at a time
|
|
170
|
+
* @param {number} limit
|
|
171
|
+
* @returns {PaginatedFetch} object with pagination methods
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
export async function fetchServicesPaginated(limit) {
|
|
175
|
+
return new PaginateFetch(
|
|
176
|
+
SERVICES,
|
|
177
|
+
null, //filter
|
|
178
|
+
[{ fieldRef: "NAME", dirStr: "asc" }], //sort
|
|
179
|
+
null, //ref
|
|
180
|
+
limit,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Fetches a single Service record by Id
|
|
186
|
+
* @param {!ServiceDescriptor.id} serviceId
|
|
187
|
+
* @returns {Promise.Service}
|
|
188
|
+
*/
|
|
189
|
+
export async function fetchService(serviceId) {
|
|
190
|
+
return fetchRecord(SERVICES, serviceId);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Fetches and returns the summarized name from a Service record
|
|
195
|
+
* @param {!string} serviceId
|
|
196
|
+
* @returns {Promise.string} the summarized name from the record
|
|
197
|
+
*/
|
|
198
|
+
export async function fetchServiceName(serviceId) {
|
|
199
|
+
const service = await fetchService(serviceId);
|
|
200
|
+
return summarizeService(service);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
//////////////////////////////////////////////////////////////////////
|
|
204
|
+
// utilities
|
|
205
|
+
/**
|
|
206
|
+
* Returns a standardized formatted name string
|
|
207
|
+
* @param {ServiceDescriptor}
|
|
208
|
+
* @returns {string} formatted name string
|
|
209
|
+
*/
|
|
210
|
+
function summarizeService(service) {
|
|
211
|
+
return `${service?.name}`;
|
|
212
|
+
}
|
package/business/User/index.js
CHANGED
|
@@ -125,7 +125,7 @@ export const createUser = (user) => {
|
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
127
|
* Builds a User record from the authentication "user" data
|
|
128
|
-
* @param {
|
|
128
|
+
* @param {UserObject} user
|
|
129
129
|
* @param {boolean} user.isAnonymous
|
|
130
130
|
* @param {?string} user.displayName
|
|
131
131
|
* @param {?string} user.photoURL
|
package/business/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export * from "./boilerplate/index.js";
|
|
7
7
|
export * from "./Addresses/index.js";
|
|
8
|
+
export * from "./AuthMachine/index.js";
|
|
8
9
|
export * from "./BusinessData/index.js";
|
|
9
10
|
export * from "./Commodities/index.js";
|
|
10
11
|
export * from "./Fundamentals/index.js";
|
|
@@ -14,5 +15,6 @@ export * from "./Messages/index.js";
|
|
|
14
15
|
export * from "./Payment/index.js";
|
|
15
16
|
export * from "./PrivateData/index.js";
|
|
16
17
|
export * from "./Product/index.js";
|
|
18
|
+
export * from "./Services/index.js";
|
|
17
19
|
export * from "./User/index.js";
|
|
18
20
|
export * from "./Utilities/index.js";
|