@onesignal/onesignal-vue3 2.1.0 → 2.2.1

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/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { App } from 'vue';
2
2
 
3
3
  const ONESIGNAL_SDK_ID = 'onesignal-sdk';
4
- const ONE_SIGNAL_SCRIPT_SRC = "https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js";
4
+ const ONE_SIGNAL_SCRIPT_SRC =
5
+ 'https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js';
5
6
 
6
7
  // true if the script is successfully loaded from CDN.
7
8
  let isOneSignalInitialized = false;
@@ -31,13 +32,13 @@ function addSDKScript() {
31
32
  // This is important for users who may block cdn.onesignal.com w/ adblock.
32
33
  script.onerror = () => {
33
34
  handleOnError();
34
- }
35
+ };
35
36
 
36
37
  document.head.appendChild(script);
37
38
  }
38
39
  /* T Y P E D E C L A R A T I O N S */
39
40
 
40
- declare module '@vue/runtime-core' {
41
+ declare module 'vue' {
41
42
  export interface ComponentCustomProperties {
42
43
  $OneSignal: IOneSignalOneSignal;
43
44
  }
@@ -53,36 +54,36 @@ declare global {
53
54
  }
54
55
  }
55
56
 
56
-
57
57
  /* O N E S I G N A L A P I */
58
58
 
59
59
  /**
60
60
  * @PublicApi
61
61
  */
62
- const init = (options: IInitObject): Promise<void> => {
62
+ const init = (options: IInitObject): Promise<void> => {
63
63
  if (isOneSignalInitialized) {
64
64
  return Promise.reject(`OneSignal is already initialized.`);
65
65
  }
66
66
 
67
67
  if (!options || !options.appId) {
68
- throw new Error('You need to provide your OneSignal appId.');
68
+ return Promise.reject('You need to provide your OneSignal appId.');
69
69
  }
70
70
 
71
71
  if (!document) {
72
72
  return Promise.reject(`Document is not defined.`);
73
73
  }
74
74
 
75
- return new Promise<void>((resolve) => {
75
+ return new Promise<void>((resolve, reject) => {
76
76
  window.OneSignalDeferred?.push((OneSignal) => {
77
- OneSignal.init(options).then(() => {
78
- isOneSignalInitialized = true;
79
- resolve();
80
- });
77
+ OneSignal.init(options)
78
+ .then(() => {
79
+ isOneSignalInitialized = true;
80
+ resolve();
81
+ })
82
+ .catch(reject);
81
83
  });
82
84
  });
83
85
  };
84
86
 
85
-
86
87
  /**
87
88
  * The following code is copied directly from the native SDK source file BrowserSupportsPush.ts
88
89
  * S T A R T
@@ -96,20 +97,26 @@ function isPushNotificationsSupported() {
96
97
 
97
98
  function isMacOSSafariInIframe(): boolean {
98
99
  // Fallback detection for Safari on macOS in an iframe context
99
- return window.top !== window && // isContextIframe
100
- navigator.vendor === "Apple Computer, Inc." && // isSafari
101
- navigator.platform === "MacIntel"; // isMacOS
100
+ return (
101
+ window.top !== window && // isContextIframe
102
+ navigator.vendor === 'Apple Computer, Inc.' && // isSafari
103
+ navigator.platform === 'MacIntel'
104
+ ); // isMacOS
102
105
  }
103
106
 
104
107
  function supportsSafariPush(): boolean {
105
- return (window.safari && typeof window.safari.pushNotification !== "undefined") ||
106
- isMacOSSafariInIframe();
108
+ return (
109
+ (window.safari && typeof window.safari.pushNotification !== 'undefined') ||
110
+ isMacOSSafariInIframe()
111
+ );
107
112
  }
108
113
 
109
114
  // Does the browser support the standard Push API
110
115
  function supportsVapidPush(): boolean {
111
- return typeof PushSubscriptionOptions !== "undefined" &&
112
- PushSubscriptionOptions.prototype.hasOwnProperty("applicationServerKey");
116
+ return (
117
+ typeof PushSubscriptionOptions !== 'undefined' &&
118
+ PushSubscriptionOptions.prototype.hasOwnProperty('applicationServerKey')
119
+ );
113
120
  }
114
121
  /* E N D */
115
122
 
@@ -118,18 +125,18 @@ function supportsVapidPush(): boolean {
118
125
  */
119
126
  const isPushSupported = (): boolean => {
120
127
  return isPushNotificationsSupported();
121
- }
128
+ };
122
129
 
123
- interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }
124
- interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }
125
- interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; }
126
- interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; }
127
- type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };
128
- type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };
129
- type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
130
- type SlidedownEventName = 'slidedownShown';
131
- type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
132
- interface IOSNotification {
130
+ export interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }
131
+ export interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }
132
+ export interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; }
133
+ export interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; }
134
+ export type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };
135
+ export type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };
136
+ export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
137
+ export type SlidedownEventName = 'slidedownAllowClick' | 'slidedownCancelClick' | 'slidedownClosed' | 'slidedownQueued' | 'slidedownShown';
138
+ export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
139
+ export interface IOSNotification {
133
140
  /**
134
141
  * The OneSignal notification id;
135
142
  * - Primary id on OneSignal's REST API and dashboard
@@ -191,7 +198,7 @@ interface IOSNotification {
191
198
  readonly confirmDelivery: boolean;
192
199
  }
193
200
 
194
- interface IOSNotificationActionButton {
201
+ export interface IOSNotificationActionButton {
195
202
  /**
196
203
  * Any unique identifier to represent which button was clicked. This is typically passed back to the service worker
197
204
  * and host page through events to identify which button was clicked.
@@ -212,12 +219,12 @@ interface IOSNotificationActionButton {
212
219
  readonly launchURL?: string;
213
220
  }
214
221
 
215
- interface NotificationClickResult {
222
+ export interface NotificationClickResult {
216
223
  readonly actionId?: string;
217
224
  readonly url?: string;
218
225
  }
219
226
 
220
- type NotificationEventTypeMap = {
227
+ export type NotificationEventTypeMap = {
221
228
  'click': NotificationClickEvent;
222
229
  'foregroundWillDisplay': NotificationForegroundWillDisplayEvent;
223
230
  'dismiss': NotificationDismissEvent;
@@ -225,37 +232,219 @@ type NotificationEventTypeMap = {
225
232
  'permissionPromptDisplay': void;
226
233
  };
227
234
 
228
- interface NotificationForegroundWillDisplayEvent {
235
+ export interface NotificationForegroundWillDisplayEvent {
229
236
  readonly notification: IOSNotification;
230
237
  preventDefault(): void;
231
238
  }
232
239
 
233
- interface NotificationDismissEvent {
240
+ export interface NotificationDismissEvent {
234
241
  notification: IOSNotification;
235
242
  }
236
243
 
237
- interface NotificationClickEvent {
244
+ export interface NotificationClickEvent {
238
245
  readonly notification: IOSNotification;
239
246
  readonly result: NotificationClickResult;
240
247
  }
241
248
 
242
- type UserChangeEvent = {
249
+ export type UserChangeEvent = {
243
250
  current: UserNamespaceProperties;
244
251
  };
245
- type UserNamespaceProperties = {
252
+ export type UserNamespaceProperties = {
246
253
  onesignalId: string | undefined;
247
254
  externalId: string | undefined;
248
255
  };
249
256
 
250
- interface IInitObject {
257
+ export interface IInitObject {
251
258
  appId: string;
252
259
  subdomainName?: string;
253
260
  requiresUserPrivacyConsent?: boolean;
254
- promptOptions?: object;
255
- welcomeNotification?: object;
256
- notifyButton?: object;
261
+ promptOptions?: {
262
+ slidedown: {
263
+ prompts: {
264
+ /**
265
+ * Whether to automatically display the prompt.
266
+ * `true` will display the prompt based on the delay options.
267
+ * `false` will prevent the prompt from displaying until the Slidedowns methods are used.
268
+ */
269
+ autoPrompt: boolean;
270
+
271
+ /**
272
+ * Only available for type: category. Up to 10 categories.
273
+ * @example
274
+ * categories: [{ tag: 'local_news', label: 'Local News' }] // The user will be tagged with local_news but will see "Local News" in the prompt.
275
+ */
276
+ categories: {
277
+ /** Should identify the action. */
278
+ tag: string;
279
+
280
+ /** What the user will see. */
281
+ label: string;
282
+ }[];
283
+
284
+ /**
285
+ * The delay options for the prompt.
286
+ * @example delay: { pageViews: 3, timeDelay: 20 } // The user will not be shown the prompt until 20 seconds after the 3rd page view.
287
+ */
288
+ delay: {
289
+ /** The number of pages a user needs to visit before the prompt is displayed. */
290
+ pageViews?: number;
291
+
292
+ /** The number of seconds a user needs to wait before the prompt is displayed.Both options must be satisfied for the prompt to display */
293
+ timeDelay?: number;
294
+ };
295
+
296
+ /**
297
+ * The text to display in the prompt.
298
+ */
299
+ text?: {
300
+ /** The callout asking the user to opt-in. Up to 90 characters. */
301
+ actionMessage?: string;
302
+
303
+ /** Triggers the opt-in. Up to 15 characters. */
304
+ acceptButton?: string;
305
+
306
+ /** Cancels opt-in. Up to 15 characters. */
307
+ cancelMessage?: string;
308
+
309
+ /** The message of the confirmation prompt displayed after the email and/or phone number is provided. Up to 90 characters. */
310
+ confirmMessage?: string;
311
+
312
+ /** Identifies the email text field. Up to 15 characters. */
313
+ emailLabel?: string;
314
+
315
+ /** Cancels the category update. Up to 15 characters. */
316
+ negativeUpdateButton?: string;
317
+
318
+ /** Saves the updated category tags. Up to 15 characters. */
319
+ positiveUpdateButton?: string;
320
+
321
+ /** Identifies the phone number text field. Up to 15 characters. */
322
+ smsLabel?: string;
323
+
324
+ /** A different message shown to subscribers presented the prompt again to update categories. Up to 90 characters. */
325
+ updateMessage?: string;
326
+ };
327
+
328
+ /**
329
+ * The type of prompt to display.
330
+ * `push` which is the Slide Prompt without categories.
331
+ * `category` which is the Slide Prompt with categories.
332
+ * `sms` only asks for phone number.
333
+ * `email` only asks for email address.
334
+ * `smsAndEmail` asks for both phone number and email address.
335
+ */
336
+ type: 'push' | 'category' | 'sms' | 'email' | 'smsAndEmail';
337
+ }[];
338
+ };
339
+ };
340
+ welcomeNotification?: {
341
+ /**
342
+ * Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need.
343
+ */
344
+ disabled?: boolean;
345
+
346
+ /**
347
+ * The welcome notification's message. You can localize this to your own language.
348
+ * If left blank or set to blank, the default of 'Thanks for subscribing!' will be used.
349
+ */
350
+ message: string;
351
+
352
+ /**
353
+ * The welcome notification's title. You can localize this to your own language. If not set, or left blank, the site's title will be used.
354
+ * Set to one space ' ' to clear the title, although this is not recommended.
355
+ */
356
+ title?: string;
357
+
358
+ /**
359
+ * By default, clicking the welcome notification does not open any link.
360
+ * This is recommended because the user has just visited your site and subscribed.
361
+ */
362
+ url: string;
363
+ };
364
+
365
+ /**
366
+ * Will enable customization of the notify/subscription bell button.
367
+ */
368
+ notifyButton?: {
369
+ /**
370
+ * A function you define that returns true to show the Subscription Bell, or false to hide it.
371
+ * Typically used the hide the Subscription Bell after the user is subscribed.
372
+ * This function is not re-evaluated on every state change; this function is only evaluated once when the Subscription Bell begins to show.
373
+ */
374
+ displayPredicate?: () => boolean | Promise<boolean>;
375
+
376
+ /**
377
+ * Enable the Subscription Bell. The Subscription Bell is otherwise disabled by default.
378
+ */
379
+ enable?: boolean;
380
+
381
+ /** Specify CSS-valid pixel offsets using bottom, left, and right. */
382
+ offset?: { bottom: string; left: string; right: string };
383
+
384
+ /**
385
+ * If `true`, the Subscription Bell will display an icon that there is 1 unread message.
386
+ * When hovering over the Subscription Bell, the user will see custom text set by message.prenotify.
387
+ */
388
+ prenotify: boolean;
389
+
390
+ /** Either `bottom-left` or `bottom-right`. The Subscription Bell will be fixed at this location on your page. */
391
+ position?: 'bottom-left' | 'bottom-right';
392
+
393
+ /** Set `false` to hide the 'Powered by OneSignal' text in the Subscription Bell dialog popup. */
394
+ showCredit: boolean;
395
+
396
+ /**
397
+ * The Subscription Bell will initially appear at one of these sizes, and then shrink down to size `small` after the user subscribes.
398
+ */
399
+ size?: 'small' | 'medium' | 'large';
400
+
401
+ /** Customize the Subscription Bell text. */
402
+ text: {
403
+ 'dialog.blocked.message': string;
404
+ 'dialog.blocked.title': string;
405
+ 'dialog.main.button.subscribe': string;
406
+ 'dialog.main.button.unsubscribe': string;
407
+ 'dialog.main.title': string;
408
+ 'message.action.resubscribed': string;
409
+ 'message.action.subscribed': string;
410
+ 'message.action.subscribing': string;
411
+ 'message.action.unsubscribed': string;
412
+ 'message.prenotify': string;
413
+ 'tip.state.blocked': string;
414
+ 'tip.state.subscribed': string;
415
+ 'tip.state.unsubscribed': string;
416
+ };
417
+ };
418
+
257
419
  persistNotification?: boolean;
258
- webhooks?: object;
420
+ webhooks?: {
421
+ /**
422
+ * Enable this setting only if your server has CORS enabled and supports non-simple CORS requests.
423
+ * If this setting is disabled, your webhook will not need CORS to receive data, but it will not receive the custom headers.
424
+ * The simplest option is to leave it disabled.
425
+ * @default false
426
+ */
427
+ cors: boolean;
428
+
429
+ /**
430
+ * This event occurs after a notification is clicked.
431
+ * @example https://site.com/hook
432
+ */
433
+ 'notification.clicked'?: string;
434
+
435
+ /**
436
+ * This event occurs after a notification is intentionally dismissed by the user (clicking the notification body or one of the notification action buttons does not trigger the dismissed webhook),
437
+ * after a group of notifications are all dismissed (with this notification as part of that group), or after a notification expires on its own time and disappears. This event is supported on Chrome only.
438
+ * @example https://site.com/hook
439
+ */
440
+ 'notification.dismissed'?: string;
441
+
442
+ /**
443
+ * This event occurs after a notification is displayed.
444
+ * @example https://site.com/hook
445
+ */
446
+ 'notification.willDisplay'?: string;
447
+ };
259
448
  autoResubscribe?: boolean;
260
449
  autoRegister?: boolean;
261
450
  notificationClickHandlerMatch?: string;
@@ -269,7 +458,7 @@ interface IInitObject {
269
458
  [key: string]: any;
270
459
  }
271
460
 
272
- interface IOneSignalOneSignal {
461
+ export interface IOneSignalOneSignal {
273
462
  Slidedown: IOneSignalSlidedown;
274
463
  Notifications: IOneSignalNotifications;
275
464
  Session: IOneSignalSession;
@@ -281,7 +470,7 @@ interface IOneSignalOneSignal {
281
470
  setConsentGiven(consent: boolean): Promise<void>;
282
471
  setConsentRequired(requiresConsent: boolean): Promise<void>;
283
472
  }
284
- interface IOneSignalNotifications {
473
+ export interface IOneSignalNotifications {
285
474
  permissionNative: NotificationPermission;
286
475
  permission: boolean;
287
476
  setDefaultUrl(url: string): Promise<void>;
@@ -291,7 +480,7 @@ interface IOneSignalNotifications {
291
480
  addEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
292
481
  removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
293
482
  }
294
- interface IOneSignalSlidedown {
483
+ export interface IOneSignalSlidedown {
295
484
  promptPush(options?: AutoPromptOptions): Promise<void>;
296
485
  promptPushCategories(options?: AutoPromptOptions): Promise<void>;
297
486
  promptSms(options?: AutoPromptOptions): Promise<void>;
@@ -300,14 +489,14 @@ interface IOneSignalSlidedown {
300
489
  addEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
301
490
  removeEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
302
491
  }
303
- interface IOneSignalDebug {
492
+ export interface IOneSignalDebug {
304
493
  setLogLevel(logLevel: string): void;
305
494
  }
306
- interface IOneSignalSession {
495
+ export interface IOneSignalSession {
307
496
  sendOutcome(outcomeName: string, outcomeWeight?: number): Promise<void>;
308
497
  sendUniqueOutcome(outcomeName: string): Promise<void>;
309
498
  }
310
- interface IOneSignalUser {
499
+ export interface IOneSignalUser {
311
500
  onesignalId: string | undefined;
312
501
  externalId: string | undefined;
313
502
  PushSubscription: IOneSignalPushSubscription;
@@ -329,7 +518,7 @@ interface IOneSignalUser {
329
518
  setLanguage(language: string): void;
330
519
  getLanguage(): string;
331
520
  }
332
- interface IOneSignalPushSubscription {
521
+ export interface IOneSignalPushSubscription {
333
522
  id: string | null | undefined;
334
523
  token: string | null | undefined;
335
524
  optedIn: boolean | undefined;
@@ -856,13 +1045,14 @@ const OneSignalNamespace: IOneSignalOneSignal = {
856
1045
 
857
1046
  export const useOneSignal = () => {
858
1047
  return OneSignalNamespace;
859
- }
1048
+ };
860
1049
 
861
1050
  const OneSignalVuePlugin = {
862
1051
  install(app: App, options: IInitObject) {
863
- app.config.globalProperties.$OneSignal = OneSignalNamespace as IOneSignalOneSignal;
1052
+ app.config.globalProperties.$OneSignal =
1053
+ OneSignalNamespace as IOneSignalOneSignal;
864
1054
  app.config.globalProperties.$OneSignal.init(options);
865
- }
866
- }
1055
+ },
1056
+ };
867
1057
 
868
1058
  export default OneSignalVuePlugin;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@onesignal/onesignal-vue3",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "description": "Vue 3 OneSignal Plugin: Make it easy to integrate OneSignal with your Vue App!",
5
- "author": "rgomezp",
5
+ "type": "module",
6
6
  "contributors": [
7
7
  {
8
8
  "name": "Rodrigo Gomez-Palacio"
@@ -16,9 +16,9 @@
16
16
  "main": "dist/index.js",
17
17
  "types": "dist/index.d.ts",
18
18
  "scripts": {
19
- "lint": "./node_modules/.bin/eslint . --ext .ts",
20
- "build": "yarn run lint && tsc",
21
- "prepare": "yarn run build"
19
+ "lint": "eslint . --ext .ts",
20
+ "build": "npm run lint && tsc",
21
+ "prepare": "npm run build"
22
22
  },
23
23
  "dependencies": {
24
24
  "vue": "^3.2.0"
package/tsconfig.json CHANGED
@@ -13,7 +13,6 @@
13
13
  "noImplicitThis": true,
14
14
  "noImplicitAny": false,
15
15
  "strictNullChecks": false,
16
- "suppressImplicitAnyIndexErrors": true,
17
16
  "noUnusedLocals": true,
18
17
  "noUnusedParameters": true,
19
18
  "allowSyntheticDefaultImports": true,
@@ -1,58 +0,0 @@
1
- import { Octokit } from "@octokit/action"
2
-
3
- /**
4
- * Based on probot-metadata - https://github.com/probot/metadata
5
- */
6
- const regex = /\n\n<!-- probot = (.*) -->/
7
-
8
- const octokit = new Octokit()
9
-
10
- module.exports = (context, issue = null) => {
11
- console.log(context)
12
- const prefix = "onesignal-probot"
13
-
14
- if (!issue) issue = context.payload.issue
15
-
16
- return {
17
- async get (key = null) {
18
- let body = issue.body
19
-
20
- if (!body) {
21
- body = (await octokit.issues.get(issue)).data.body || ''
22
- }
23
-
24
- const match = body.match(regex)
25
-
26
- if (match) {
27
- const data = JSON.parse(match[1])[prefix]
28
- return key ? data && data[key] : data
29
- }
30
- },
31
-
32
- async set (key, value) {
33
- let body = issue.body
34
- let data = {}
35
-
36
- if (!body) body = (await octokit.issues.get(issue)).data.body || ''
37
-
38
- body = body.replace(regex, (_, json) => {
39
- data = JSON.parse(json)
40
- return ''
41
- })
42
-
43
- if (!data[prefix]) data[prefix] = {}
44
-
45
- if (typeof key === 'object') {
46
- Object.assign(data[prefix], key)
47
- } else {
48
- data[prefix][key] = value
49
- }
50
-
51
- body = `${body}\n\n<!-- probot = ${JSON.stringify(data)} -->`
52
-
53
- const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/")
54
- const issue_number = context.payload.issue.number
55
- return octokit.issues.update({ owner, repo, issue_number, body })
56
- }
57
- }
58
- }
@@ -1,47 +0,0 @@
1
- function calcResponseTimeForIssueCreatedAt(createdAt) {
2
- const issueOpenedDate = new Date(createdAt);
3
- const issueTriagedDate = new Date();
4
- const businessDaysResponseTime = calcBusinessDaysBetweenDates(issueOpenedDate, issueTriagedDate);
5
- return businessDaysResponseTime;
6
- }
7
-
8
- function calcBusinessDaysBetweenDates(openedDate, triagedDate) {
9
- let differenceInWeeks, responseTime;
10
- if (triagedDate < openedDate)
11
- return -1; // error code if dates transposed
12
- let openedDay = openedDate.getDay(); // day of week
13
- let triagedDay = triagedDate.getDay();
14
- openedDay = (openedDay == 0) ? 7 : openedDay; // change Sunday from 0 to 7
15
- triagedDay = (triagedDay == 0) ? 7 : triagedDay;
16
- openedDay = (openedDay > 5) ? 5 : openedDay; // only count weekdays
17
- triagedDay = (triagedDay > 5) ? 5 : triagedDay;
18
- // calculate differnece in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)
19
- differenceInWeeks = Math.floor((triagedDate.getTime() - openedDate.getTime()) / 604800000);
20
- if (openedDay < triagedDay) { //Equal to makes it reduce 5 days
21
- responseTime = (differenceInWeeks * 5) + (triagedDay - openedDay);
22
- }
23
- else if (openedDay == triagedDay) {
24
- responseTime = differenceInWeeks * 5;
25
- }
26
- else {
27
- responseTime = ((differenceInWeeks + 1) * 5) - (openedDay - triagedDay);
28
- }
29
- return (responseTime);
30
- }
31
-
32
- module.exports = async(context, osmetadata) => {
33
- const foundResponseTime = await osmetadata(context).get('response_time_in_business_days');
34
- if (foundResponseTime) {
35
- const foundString = "already found response time in business days: " + foundResponseTime
36
- console.log(foundString);
37
- return foundString;
38
- }
39
- if (context.payload.comment && context.payload.comment.author_association != "MEMBER" && context.payload.comment.author_association != "OWNER" && context.payload.comment.author_association != "CONTRIBUTOR") {
40
- return;
41
- }
42
- const businessDaysResponseTime = calcResponseTimeForIssueCreatedAt(context.payload.issue.created_at);
43
- console.log("response time in business days: " + businessDaysResponseTime);
44
- const result = osmetadata(context, context.payload.issue).set('response_time_in_business_days', businessDaysResponseTime)
45
- console.log("osmetadata update result: " + result);
46
- return "set response time in business days: " + businessDaysResponseTime;
47
- }
@@ -1,34 +0,0 @@
1
- # This is an action to close asana tasks that were generated by Github issues
2
-
3
- name: Zapier web hook
4
-
5
- # Controls when the workflow will run
6
- on:
7
- # Triggers the workflow on push or pull request events but only for the "main" branch
8
- issues:
9
- types: [closed]
10
-
11
- permissions:
12
- issues: read
13
-
14
- # A workflow run is made up of one or more jobs that can run sequentially or in parallel
15
- jobs:
16
- # This workflow contains a single job called "build"
17
- build:
18
- # The type of runner that the job will run on
19
- runs-on: ubuntu-latest
20
-
21
- # Steps represent a sequence of tasks that will be executed as part of the job
22
- steps:
23
- # Runs a set of commands using the runners shell
24
- - name: Call Zapier web hook to close Asana task
25
- if: ${{ !github.event.issue.pull_request }}
26
- env:
27
- ISSUE_TITLE: ${{ github.event.issue.title }}
28
- run: |
29
- curl --location --request POST 'https://hooks.zapier.com/hooks/catch/12728683/b7009qc/' \
30
- --header 'Content-Type: application/json' \
31
- --header 'Accept: application/json' \
32
- --data-raw '{
33
- "task_name" : "$ISSUE_TITLE"
34
- }'
@@ -1,41 +0,0 @@
1
- name: Release Drafter
2
-
3
- on:
4
- push:
5
- # branches to consider in the event; optional, defaults to all
6
- branches:
7
- - main
8
- # pull_request event is required only for autolabeler
9
- pull_request:
10
- # Only following types are handled by the action, but one can default to all as well
11
- types: [opened, reopened, synchronize]
12
- # pull_request_target event is required for autolabeler to support PRs from forks
13
- # pull_request_target:
14
- # types: [opened, reopened, synchronize]
15
-
16
- permissions:
17
- contents: read
18
-
19
- jobs:
20
- update_release_draft:
21
- permissions:
22
- # write permission is required to create a github release
23
- contents: write
24
- # write permission is required for autolabeler
25
- # otherwise, read permission is required at least
26
- pull-requests: write
27
- runs-on: ubuntu-latest
28
- steps:
29
- # (Optional) GitHub Enterprise requires GHE_HOST variable set
30
- #- name: Set GHE_HOST
31
- # run: |
32
- # echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV
33
-
34
- # Drafts your next Release notes as Pull Requests are merged into "master"
35
- - uses: release-drafter/release-drafter@v5
36
- # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
37
- # with:
38
- # config-name: my-config.yml
39
- # disable-autolabeler: true
40
- env:
41
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}