Skip to content

Commit 40e9973

Browse files
committed
prodatakey init
1 parent 101957f commit 40e9973

File tree

7 files changed

+601
-6
lines changed

7 files changed

+601
-6
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import prodatakey from "../../prodatakey.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "prodatakey-create-customer",
6+
name: "Create Customer",
7+
description: "Creates a new customer in the ProdataKey system. [See the documentation](https://developer.pdk.io/web/2.0/rest/organizations)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
prodatakey,
12+
dealerId: {
13+
propDefinition: [
14+
prodatakey,
15+
"dealerId",
16+
],
17+
},
18+
name: {
19+
type: "string",
20+
label: "Name",
21+
description: "The name of the customer to be created",
22+
},
23+
useBluetoothCredentials: {
24+
propDefinition: [
25+
prodatakey,
26+
"useBluetoothCredentials",
27+
],
28+
optional: true,
29+
},
30+
useTouchMobileApp: {
31+
propDefinition: [
32+
prodatakey,
33+
"useTouchMobileApp",
34+
],
35+
optional: true,
36+
},
37+
allowCredentialResets: {
38+
propDefinition: [
39+
prodatakey,
40+
"allowCredentialResets",
41+
],
42+
optional: true,
43+
},
44+
type: {
45+
propDefinition: [
46+
prodatakey,
47+
"type",
48+
],
49+
optional: true,
50+
},
51+
},
52+
async run({ $ }) {
53+
const response = await this.prodatakey.createCustomer({
54+
dealerId: this.dealerId,
55+
name: this.name,
56+
useBluetoothCredentials: this.useBluetoothCredentials,
57+
useTouchMobileApp: this.useTouchMobileApp,
58+
allowCredentialResets: this.allowCredentialResets,
59+
type: this.type,
60+
});
61+
62+
$.export("$summary", `Successfully created customer with ID: ${response.id}`);
63+
return response;
64+
},
65+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import prodatakey from "../../prodatakey.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "prodatakey-retrieve-credential",
6+
name: "Retrieve Credential",
7+
description: "Retrieve a specific credential using the system ID, holder ID, and credential ID. [See the documentation](https://developer.pdk.io/web/2.0/rest/credentials)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
prodatakey,
12+
systemId: {
13+
type: "string",
14+
label: "System ID",
15+
},
16+
holderId: {
17+
type: "string",
18+
label: "Holder ID",
19+
},
20+
credentialId: {
21+
propDefinition: [
22+
prodatakey,
23+
"credentialId",
24+
(c) => ({
25+
systemId: c.systemId,
26+
holderId: c.holderId,
27+
}),
28+
],
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.prodatakey.retrieveCredential({
33+
systemId: this.systemId,
34+
holderId: this.holderId,
35+
credentialId: this.credentialId,
36+
});
37+
38+
$.export("$summary", `Successfully retrieved credential with ID ${response.id}`);
39+
return response;
40+
},
41+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import prodatakey from "../../prodatakey.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "prodatakey-retrieve-organization",
6+
name: "Retrieve Organization",
7+
description: "Retrieve an existing organization. [See the documentation](https://developer.pdk.io/web/2.0/rest/organizations)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
prodatakey,
12+
organizationId: {
13+
propDefinition: [
14+
prodatakey,
15+
"organizationId",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.prodatakey.retrieveOrganization({
21+
organizationId: this.organizationId,
22+
});
23+
24+
$.export("$summary", `Successfully retrieved organization: ${response.name}`);
25+
return response;
26+
},
27+
};

components/prodatakey/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 209 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,215 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "prodatakey",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
organizationId: {
8+
type: "string",
9+
label: "Organization ID",
10+
async options() {
11+
const organizations = await this.listOrganizations();
12+
return organizations.map((org) => ({
13+
label: org.name,
14+
value: org.id,
15+
}));
16+
},
17+
},
18+
dealerId: {
19+
type: "string",
20+
label: "Dealer ID",
21+
async options() {
22+
const dealers = await this.listDealers();
23+
return dealers.map((dealer) => ({
24+
label: dealer.name,
25+
value: dealer.id,
26+
}));
27+
},
28+
},
29+
credentialId: {
30+
type: "string",
31+
label: "Credential ID",
32+
async options({
33+
systemId, holderId,
34+
}) {
35+
const credentials = await this.listCredentials({
36+
systemId,
37+
holderId,
38+
});
39+
return credentials.map((credential) => ({
40+
label: credential.id,
41+
value: credential.id,
42+
}));
43+
},
44+
},
45+
systemId: {
46+
type: "string",
47+
label: "System ID",
48+
},
49+
holderId: {
50+
type: "string",
51+
label: "Holder ID",
52+
},
53+
name: {
54+
type: "string",
55+
label: "Name",
56+
},
57+
url: {
58+
type: "string",
59+
label: "URL",
60+
},
61+
scope: {
62+
type: "string",
63+
label: "Scope",
64+
},
65+
authenticationType: {
66+
type: "string",
67+
label: "Authentication Type",
68+
},
69+
events: {
70+
type: "string[]",
71+
label: "Events",
72+
optional: true,
73+
},
74+
authenticationUser: {
75+
type: "string",
76+
label: "Authentication User",
77+
optional: true,
78+
},
79+
authenticationPassword: {
80+
type: "string",
81+
label: "Authentication Password",
82+
optional: true,
83+
},
84+
secret: {
85+
type: "string",
86+
label: "Secret",
87+
optional: true,
88+
},
89+
useBluetoothCredentials: {
90+
type: "boolean",
91+
label: "Use Bluetooth Credentials",
92+
optional: true,
93+
},
94+
useTouchMobileApp: {
95+
type: "boolean",
96+
label: "Use Touch Mobile App",
97+
optional: true,
98+
},
99+
allowCredentialResets: {
100+
type: "boolean",
101+
label: "Allow Credential Resets",
102+
optional: true,
103+
},
104+
type: {
105+
type: "string",
106+
label: "Type",
107+
optional: true,
108+
},
109+
},
5110
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
111+
_baseUrl() {
112+
return "https://accounts.pdk.io/api";
113+
},
114+
async _makeRequest(opts = {}) {
115+
const {
116+
$ = this, method = "GET", path, headers, ...otherOpts
117+
} = opts;
118+
return axios($, {
119+
...otherOpts,
120+
method,
121+
url: this._baseUrl() + path,
122+
headers: {
123+
...headers,
124+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
125+
},
126+
});
127+
},
128+
async listOrganizations(opts = {}) {
129+
return this._makeRequest({
130+
path: "/organizations",
131+
...opts,
132+
});
133+
},
134+
async listDealers(opts = {}) {
135+
return this._makeRequest({
136+
path: "/dealers",
137+
...opts,
138+
});
139+
},
140+
async listCredentials(opts = {}) {
141+
const {
142+
systemId, holderId,
143+
} = opts;
144+
return this._makeRequest({
145+
path: `/systems/${systemId}/holders/${holderId}/credentials`,
146+
});
147+
},
148+
async createCustomer({
149+
dealerId, name, useBluetoothCredentials, useTouchMobileApp, allowCredentialResets, type,
150+
}) {
151+
return this._makeRequest({
152+
method: "POST",
153+
path: `/organizations/${dealerId}/children`,
154+
data: {
155+
name,
156+
useBluetoothCredentials,
157+
useTouchMobileApp,
158+
allowCredentialResets,
159+
type,
160+
},
161+
});
162+
},
163+
async retrieveOrganization({ organizationId }) {
164+
return this._makeRequest({
165+
path: `/organizations/${organizationId}`,
166+
});
167+
},
168+
async retrieveCredential({
169+
systemId, holderId, credentialId,
170+
}) {
171+
return this._makeRequest({
172+
path: `/systems/${systemId}/holders/${holderId}/credentials/${credentialId}`,
173+
});
174+
},
175+
async emitEventCloudNodeConnected({
176+
organizationId, name, url, scope, authenticationType, authenticationUser, authenticationPassword, secret,
177+
}) {
178+
return this._makeRequest({
179+
method: "POST",
180+
path: "/events",
181+
data: {
182+
event_type: "cloudnode.connected",
183+
organization_id: organizationId,
184+
name,
185+
url,
186+
scope,
187+
authentication_type: authenticationType,
188+
authentication_user: authenticationUser,
189+
authentication_password: authenticationPassword,
190+
secret,
191+
},
192+
});
193+
},
194+
async emitEvent({
195+
organizationId, name, url, scope, authenticationType, events, authenticationUser, authenticationPassword, secret,
196+
}) {
197+
const eventPromises = events.map((event) => this._makeRequest({
198+
method: "POST",
199+
path: "/events",
200+
data: {
201+
event_type: event,
202+
organization_id: organizationId,
203+
name,
204+
url,
205+
scope,
206+
authentication_type: authenticationType,
207+
authentication_user: authenticationUser,
208+
authentication_password: authenticationPassword,
209+
secret,
210+
},
211+
}));
212+
return Promise.all(eventPromises);
9213
},
10214
},
11-
};
215+
};

0 commit comments

Comments
 (0)