@kubun/connector-google-contacts 0.8.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/LICENSE.md +57 -0
- package/lib/actions.d.ts +9 -0
- package/lib/actions.js +1 -0
- package/lib/api.d.ts +49 -0
- package/lib/api.js +1 -0
- package/lib/connector.d.ts +5 -0
- package/lib/connector.js +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +1 -0
- package/lib/model.d.ts +61 -0
- package/lib/model.js +1 -0
- package/lib/provider.d.ts +6 -0
- package/lib/provider.js +1 -0
- package/package.json +34 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# The Prosperity Public License 3.0.0
|
|
2
|
+
|
|
3
|
+
Contributor: Paul Le Cam
|
|
4
|
+
|
|
5
|
+
Source Code: https://github.com/PaulLeCam/kubun
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.
|
|
10
|
+
|
|
11
|
+
## Agreement
|
|
12
|
+
|
|
13
|
+
In order to receive this license, you have to agree to its rules. Those rules are both obligations under that agreement and conditions to your license. Don't do anything with this software that triggers a rule you can't or won't follow.
|
|
14
|
+
|
|
15
|
+
## Notices
|
|
16
|
+
|
|
17
|
+
Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
|
|
18
|
+
|
|
19
|
+
## Commercial Trial
|
|
20
|
+
|
|
21
|
+
Limit your use of this software for commercial purposes to a thirty-day trial period. If you use this software for work, your company gets one trial period for all personnel, not one trial per person.
|
|
22
|
+
|
|
23
|
+
## Contributions Back
|
|
24
|
+
|
|
25
|
+
Developing feedback, changes, or additions that you contribute back to the contributor on the terms of a standardized public software license such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html) doesn't count as use for a commercial purpose.
|
|
26
|
+
|
|
27
|
+
## Personal Uses
|
|
28
|
+
|
|
29
|
+
Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn't count as use for a commercial purpose.
|
|
30
|
+
|
|
31
|
+
## Noncommercial Organizations
|
|
32
|
+
|
|
33
|
+
Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution doesn't count as use for a commercial purpose regardless of the source of funding or obligations resulting from the funding.
|
|
34
|
+
|
|
35
|
+
## Defense
|
|
36
|
+
|
|
37
|
+
Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
|
|
38
|
+
|
|
39
|
+
## Copyright
|
|
40
|
+
|
|
41
|
+
The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
|
|
42
|
+
|
|
43
|
+
## Patent
|
|
44
|
+
|
|
45
|
+
The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
|
|
46
|
+
|
|
47
|
+
## Reliability
|
|
48
|
+
|
|
49
|
+
The contributor can't revoke this license.
|
|
50
|
+
|
|
51
|
+
## Excuse
|
|
52
|
+
|
|
53
|
+
You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
|
|
54
|
+
|
|
55
|
+
## No Liability
|
|
56
|
+
|
|
57
|
+
***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
|
package/lib/actions.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ActionHandler } from '@kubun/connector';
|
|
2
|
+
export type GoogleContactsActionHandlerConfig = {
|
|
3
|
+
credential: {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
scopes: Array<string>;
|
|
6
|
+
};
|
|
7
|
+
fetch?: typeof globalThis.fetch;
|
|
8
|
+
};
|
|
9
|
+
export declare function createGoogleContactsActionHandler(config: GoogleContactsActionHandlerConfig): ActionHandler;
|
package/lib/actions.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createContact as e,updateContact as c}from"./api.js";export function createGoogleContactsActionHandler(t){return{create:async(c,a)=>e({accessToken:t.credential.accessToken,params:a,fetch:t.fetch}),update:async(e,a,n)=>c({accessToken:t.credential.accessToken,sourceID:a,params:n,fetch:t.fetch})}}
|
package/lib/api.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { EntityRecord } from '@kubun/connector';
|
|
2
|
+
export type GooglePersonResource = {
|
|
3
|
+
resourceName: string;
|
|
4
|
+
etag?: string;
|
|
5
|
+
names?: Array<{
|
|
6
|
+
displayName?: string;
|
|
7
|
+
givenName?: string;
|
|
8
|
+
familyName?: string;
|
|
9
|
+
}>;
|
|
10
|
+
emailAddresses?: Array<{
|
|
11
|
+
value?: string;
|
|
12
|
+
}>;
|
|
13
|
+
phoneNumbers?: Array<{
|
|
14
|
+
value?: string;
|
|
15
|
+
}>;
|
|
16
|
+
organizations?: Array<{
|
|
17
|
+
name?: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
}>;
|
|
20
|
+
photos?: Array<{
|
|
21
|
+
url?: string;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
export type GoogleConnectionsResponse = {
|
|
25
|
+
connections?: Array<GooglePersonResource>;
|
|
26
|
+
nextPageToken?: string;
|
|
27
|
+
nextSyncToken?: string;
|
|
28
|
+
totalPeople?: number;
|
|
29
|
+
};
|
|
30
|
+
export declare function buildListURL(params: {
|
|
31
|
+
pageToken?: string;
|
|
32
|
+
syncToken?: string;
|
|
33
|
+
pageSize?: number;
|
|
34
|
+
}): string;
|
|
35
|
+
export declare function mapPersonToEntity(person: GooglePersonResource): EntityRecord;
|
|
36
|
+
export declare function buildPersonFromParams(params: Record<string, unknown>): Partial<GooglePersonResource>;
|
|
37
|
+
export type CreateContactParams = {
|
|
38
|
+
accessToken: string;
|
|
39
|
+
params: Record<string, unknown>;
|
|
40
|
+
fetch?: typeof globalThis.fetch;
|
|
41
|
+
};
|
|
42
|
+
export declare function createContact(options: CreateContactParams): Promise<EntityRecord>;
|
|
43
|
+
export type UpdateContactParams = {
|
|
44
|
+
accessToken: string;
|
|
45
|
+
sourceID: string;
|
|
46
|
+
params: Record<string, unknown>;
|
|
47
|
+
fetch?: typeof globalThis.fetch;
|
|
48
|
+
};
|
|
49
|
+
export declare function updateContact(options: UpdateContactParams): Promise<EntityRecord>;
|
package/lib/api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e="names,emailAddresses,phoneNumbers,organizations,photos",o="https://people.googleapis.com/v1";async function a(e){try{let o=await e.json();return o.error?.message??`${e.status} ${e.statusText}`}catch{return`${e.status} ${e.statusText}`}}export function buildListURL(a){let t=new URL(`${o}/people/me/connections`);return t.searchParams.set("personFields",e),t.searchParams.set("pageSize",String(a.pageSize??100)),null!=a.syncToken&&t.searchParams.set("syncToken",a.syncToken),t.searchParams.set("requestSyncToken","true"),null!=a.pageToken&&t.searchParams.set("pageToken",a.pageToken),t.toString()}export function mapPersonToEntity(e){return{sourceService:"google-contacts",sourceID:e.resourceName,displayName:e.names?.[0]?.displayName??"",email:e.emailAddresses?.[0]?.value??void 0,phoneNumber:e.phoneNumbers?.[0]?.value??void 0,organization:e.organizations?.[0]?.name??void 0,jobTitle:e.organizations?.[0]?.title??void 0,photoURL:e.photos?.[0]?.url??void 0,sourceURL:`https://contacts.google.com/person/${e.resourceName.replace("people/","")}`}}export function buildPersonFromParams(e){let o={};return null!=e.displayName&&(o.names=[{givenName:e.displayName}]),null!=e.email&&(o.emailAddresses=[{value:e.email}]),null!=e.phoneNumber&&(o.phoneNumbers=[{value:e.phoneNumber}]),(null!=e.organization||null!=e.jobTitle)&&(o.organizations=[{...null!=e.organization?{name:e.organization}:{},...null!=e.jobTitle?{title:e.jobTitle}:{}}]),o}export async function createContact(t){let n=t.fetch??globalThis.fetch,r=buildPersonFromParams(t.params),s=await n(`${o}/people:createContact?personFields=${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!s.ok){let e=await a(s);throw Error(`Google People API error: ${e}`)}return mapPersonToEntity(await s.json())}export async function updateContact(t){let n=t.fetch??globalThis.fetch,r=`${o}/${t.sourceID}?personFields=${e}`,s=await n(r,{headers:{Authorization:`Bearer ${t.accessToken}`}});if(!s.ok){let e=await a(s);throw Error(`Google People API error: ${e}`)}let i=await s.json(),l=buildPersonFromParams(t.params);l.etag=i.etag;let u=[];null!=l.names&&u.push("names"),null!=l.emailAddresses&&u.push("emailAddresses"),null!=l.phoneNumbers&&u.push("phoneNumbers"),null!=l.organizations&&u.push("organizations");let p=`${o}/${t.sourceID}:updateContact?updatePersonFields=${u.join(",")}&personFields=${e}`,c=await n(p,{method:"PATCH",headers:{Authorization:`Bearer ${t.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify(l)});if(!c.ok){let e=await a(c);throw Error(`Google People API error: ${e}`)}return mapPersonToEntity(await c.json())}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ConnectorDefinition } from '@kubun/connector';
|
|
2
|
+
export type CreateGoogleContactsConnectorOptions = {
|
|
3
|
+
fetch?: typeof globalThis.fetch;
|
|
4
|
+
};
|
|
5
|
+
export declare function createGoogleContactsConnector(options?: CreateGoogleContactsConnectorOptions): ConnectorDefinition;
|
package/lib/connector.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createGoogleContactsActionHandler as e}from"./actions.js";import{googleContactsClusters as t}from"./model.js";import{createGoogleContactsProvider as o}from"./provider.js";export function createGoogleContactsConnector(r){return{name:"google-contacts",version:"1.0.0",clusters:t,syncStrategies:["on-demand"],auth:{provider:"google",scopes:["https://www.googleapis.com/auth/contacts.readonly"],writeScopes:["https://www.googleapis.com/auth/contacts"]},actions:[{name:"create",description:"Create a new Google Contact",entityModel:"GoogleContact",requiresCredential:!0,input:{type:"object",properties:{displayName:{type:"string"},email:{type:"string"},phoneNumber:{type:"string"},organization:{type:"string"},jobTitle:{type:"string"}},required:["displayName"]}},{name:"update",description:"Update an existing Google Contact",entityModel:"GoogleContact",requiresCredential:!0,input:{type:"object",properties:{sourceID:{type:"string"},displayName:{type:"string"},email:{type:"string"},phoneNumber:{type:"string"},organization:{type:"string"},jobTitle:{type:"string"}},required:["sourceID"]}}],actionHandler:t=>e({credential:t.credential,fetch:r?.fetch}),serverProvider:e=>o({credential:e.credential,fetch:r?.fetch})}}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createGoogleContactsActionHandler, type GoogleContactsActionHandlerConfig, } from './actions.js';
|
|
2
|
+
export { buildListURL, buildPersonFromParams, type CreateContactParams, createContact, type GoogleConnectionsResponse, type GooglePersonResource, mapPersonToEntity, type UpdateContactParams, updateContact, } from './api.js';
|
|
3
|
+
export { type CreateGoogleContactsConnectorOptions, createGoogleContactsConnector, } from './connector.js';
|
|
4
|
+
export { googleContactDefinition, googleContactsClusters } from './model.js';
|
|
5
|
+
export { createGoogleContactsProvider, type GoogleContactsProviderConfig } from './provider.js';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{createGoogleContactsActionHandler}from"./actions.js";export{buildListURL,buildPersonFromParams,createContact,mapPersonToEntity,updateContact}from"./api.js";export{createGoogleContactsConnector}from"./connector.js";export{googleContactDefinition,googleContactsClusters}from"./model.js";export{createGoogleContactsProvider}from"./provider.js";
|
package/lib/model.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export declare const googleContactDefinition: {
|
|
2
|
+
readonly name: "GoogleContact";
|
|
3
|
+
readonly behavior: "default";
|
|
4
|
+
readonly interfaces: [string, string];
|
|
5
|
+
readonly schema: {
|
|
6
|
+
readonly type: "object";
|
|
7
|
+
readonly properties: {
|
|
8
|
+
readonly displayName: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
};
|
|
11
|
+
readonly sourceService: {
|
|
12
|
+
readonly $ref: "#/definitions/SourceService";
|
|
13
|
+
};
|
|
14
|
+
readonly sourceID: {
|
|
15
|
+
readonly $ref: "#/definitions/SourceID";
|
|
16
|
+
};
|
|
17
|
+
readonly lastSyncedAt: {
|
|
18
|
+
readonly $ref: "#/definitions/DateTime";
|
|
19
|
+
};
|
|
20
|
+
readonly sourceURL: {
|
|
21
|
+
readonly $ref: "#/definitions/SourceURL";
|
|
22
|
+
};
|
|
23
|
+
readonly email: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
};
|
|
26
|
+
readonly phoneNumber: {
|
|
27
|
+
readonly type: "string";
|
|
28
|
+
};
|
|
29
|
+
readonly organization: {
|
|
30
|
+
readonly type: "string";
|
|
31
|
+
};
|
|
32
|
+
readonly jobTitle: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
};
|
|
35
|
+
readonly photoURL: {
|
|
36
|
+
readonly $ref: "#/definitions/PhotoURL";
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
readonly required: ["sourceService", "sourceID", "lastSyncedAt"];
|
|
40
|
+
readonly additionalProperties: false;
|
|
41
|
+
readonly definitions: {
|
|
42
|
+
readonly SourceService: {
|
|
43
|
+
readonly type: "string";
|
|
44
|
+
readonly title: "SourceService";
|
|
45
|
+
readonly minLength: 1;
|
|
46
|
+
readonly maxLength: 50;
|
|
47
|
+
};
|
|
48
|
+
readonly SourceID: {
|
|
49
|
+
readonly type: "string";
|
|
50
|
+
readonly title: "SourceID";
|
|
51
|
+
readonly minLength: 1;
|
|
52
|
+
readonly maxLength: 500;
|
|
53
|
+
};
|
|
54
|
+
readonly SourceURL: import("json-schema-typed").JSONSchema.String;
|
|
55
|
+
readonly PhotoURL: import("json-schema-typed").JSONSchema.String;
|
|
56
|
+
readonly DateTime: import("json-schema-typed").JSONSchema.String;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
readonly fieldsMeta: {};
|
|
60
|
+
};
|
|
61
|
+
export declare const googleContactsClusters: import("@kubun/protocol").ClustersRecord;
|
package/lib/model.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{connectorClusters as e,connectorModelIDs as t}from"@kubun/connector";import{modelIDs as o,modelsClusters as i}from"@kubun/models";import{GraphBuilder as r}from"@kubun/protocol";import{dateTimeSchema as n,urlSchema as s}from"@kubun/scalars";export const googleContactDefinition={name:"GoogleContact",behavior:"default",interfaces:[t.ExternalEntity,o.ContactKind],schema:{type:"object",properties:{displayName:{type:"string"},sourceService:{$ref:"#/definitions/SourceService"},sourceID:{$ref:"#/definitions/SourceID"},lastSyncedAt:{$ref:"#/definitions/DateTime"},sourceURL:{$ref:"#/definitions/SourceURL"},email:{type:"string"},phoneNumber:{type:"string"},organization:{type:"string"},jobTitle:{type:"string"},photoURL:{$ref:"#/definitions/PhotoURL"}},required:["sourceService","sourceID","lastSyncedAt"],additionalProperties:!1,definitions:{SourceService:{type:"string",title:"SourceService",minLength:1,maxLength:50},SourceID:{type:"string",title:"SourceID",minLength:1,maxLength:500},SourceURL:s,PhotoURL:s,DateTime:n}},fieldsMeta:{}};let c=new r({externalClusters:{...e,...i}});c.add(googleContactDefinition);export const googleContactsClusters=c.build();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Credential, ServerDataProvider } from '@kubun/connector';
|
|
2
|
+
export type GoogleContactsProviderConfig = {
|
|
3
|
+
credential: Credential;
|
|
4
|
+
fetch?: typeof globalThis.fetch;
|
|
5
|
+
};
|
|
6
|
+
export declare function createGoogleContactsProvider(config: GoogleContactsProviderConfig): ServerDataProvider;
|
package/lib/provider.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{resolveModelID as e}from"@kubun/connector";import{buildListURL as n,mapPersonToEntity as o}from"./api.js";import{googleContactsClusters as t}from"./model.js";let l=e(t,"GoogleContact");export function createGoogleContactsProvider(e){let t=e.fetch??globalThis.fetch;async function a(o){let l=n({pageToken:o.pageToken,syncToken:o.syncToken}),a=await t(l,{headers:{Authorization:`Bearer ${e.credential.accessToken}`},signal:o.signal});if(!a.ok)throw Error(`Google People API error: ${a.status} ${a.statusText}`);return await a.json()}async function*i(e){let n,t;do{let i=await a({pageToken:n,signal:e.signal}),c=(i.connections??[]).map(o);n=i.nextPageToken,t=i.nextSyncToken,yield{modelID:l,entities:c,hasMore:null!=n,checkpoint:t}}while(null!=n)}return{supportedStrategies:["on-demand"],fetchAll:i,async *fetchChanges(e){let n,t=e.checkpoint;if(null==t)return void(yield*i(e));do{let i=await a({pageToken:n,syncToken:null!=n?void 0:t,signal:e.signal}),c=(i.connections??[]).map(o);n=i.nextPageToken,yield{modelID:l,entities:c,hasMore:null!=n,checkpoint:i.nextSyncToken}}while(null!=n)}}}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubun/connector-google-contacts",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"license": "see LICENSE.md",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"lib/*",
|
|
14
|
+
"LICENSE.md"
|
|
15
|
+
],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@kubun/connector": "^0.8.0",
|
|
19
|
+
"@kubun/models": "^0.8.0",
|
|
20
|
+
"@kubun/provider-google": "^0.8.0",
|
|
21
|
+
"@kubun/protocol": "^0.8.0",
|
|
22
|
+
"@kubun/scalars": "^0.8.0"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build:clean": "del lib",
|
|
26
|
+
"build:js": "swc src -d ./lib --config-file ../../swc.json --strip-leading-paths",
|
|
27
|
+
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
|
|
28
|
+
"build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
|
|
29
|
+
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|
|
30
|
+
"test:types": "tsc --noEmit -p tsconfig.test.json",
|
|
31
|
+
"test:unit": "vitest run",
|
|
32
|
+
"test": "pnpm run test:types && pnpm run test:unit"
|
|
33
|
+
}
|
|
34
|
+
}
|